Raised This Month: $ Target: $400
 0% 

Random numbers without repeating


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-02-2016 , 14:32   Re: Random numbers without repeating
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
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 .001795milliseconds 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 
i5i++)
  
add(tmpmsg15,"%i "randomnum[i])

server_print(tmpmsg); 

Last edited by siriusmd99; 05-02-2016 at 14:33.
siriusmd99 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode