2 registered members (OptimusPrime, AndrewAMD),
14,595
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: While statements
[Re: ventilator]
#320430
04/21/10 18:19
04/21/10 18:19
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
yes it has random runtime but at best it can loop 10*10 = 100 times, considering that the heaviest stuff in the loop is random function, length diffrence of that loop is negligible.
3333333333
|
|
|
Re: While statements
[Re: Widi]
#320485
04/21/10 21:35
04/21/10 21:35
|
Joined: Apr 2010
Posts: 20
Icarni
OP
Newbie
|
OP
Newbie
Joined: Apr 2010
Posts: 20
|
|
|
|
Re: While statements
[Re: Icarni]
#320572
04/22/10 18:09
04/22/10 18:09
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
yes, sorry, i didn't test my script... here is a corrected version:
void main()
{
randomize();
int n;
int numbers[10];
int array[192];
for(n=0; n<192; n++) array[n] = n + 1; // fill array with 1..192
for(n=0; n<10; n++)
{
int index = random((191-n)+1);
numbers[n] = array[index];
array[index] = array[191-n]; // remove the number from the array by replacing it with the last one in the array (the last one won't be accessed anymore)
}
printf("%d %d %d %d %d %d %d %d %d %d", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5], numbers[6], numbers[7], numbers[8], numbers[9]);
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|