Quote:
Originally Posted by Black Rose
Don't worry too much about efficiency here.
I ran this code 1 000 000 times with the result of 1.795s. (That's an average of .001795 milliseconds per time you randomize 5 numbers... trivial.)
Code:
for ( new i ; i < sizeof num ; i++ ) {
do num[i] = random_num(1, 10);
while ( AlreadyExists(num[i], num, i) )
}
// ...
AlreadyExists(num, array[], size) {
for ( new i ; i < size ; i++ )
if ( array[i] == num )
return 1;
return 0;
}
|
Loooool, we have the same thoughts...., gj..
Also @KiLLeR., you can avoid this thing:
Quote:
|
server_print("%i %i %i %i %i", randomnum[0], randomnum[1],randomnum[2],randomnum[3],randomnum[4]);
|
by using this :
PHP Code:
new tmpmsg[16]
for(new i; i < 5; i++)
add(tmpmsg, 15,"%i ", randomnum[i])
server_print(tmpmsg);