|
From: Sudhir K K. <ks...@ly...> - 2003-06-18 22:38:53
|
> >Greets, Artificial Stupidity, I'm Real Happy (to meet you). > >> HI, does anyone know a good way to use rnd() to generate non-repeating >random numbers - in the area of about a thousand. > > rand()%1000; // Gives a number from 0 - 999 > >Also, at the beginning of the program, do > > srand(time(NULL)); > >This is to initialize (seed) the random number so that you get different >sequences everytime you run the program. May be it is a little better to use the time in micro/milliseconds in some form as the seed instead of time (NULL) which returns seconds. This will make sure that two instances of the program started almost the same time will not get the same random number sequence. In SVR4/BSD, gettimeofday will do the trick but not sure what is the POSIX way of getting microseconds. Sudhir > >HTH. >________________________________________ > >Abhijit Shylanath >http://mudeth.tripod.com/ > > > >------------------------------------------------------- >This SF.Net email is sponsored by: INetU >Attention Web Developers & Consultants: Become An INetU Hosting Partner. >Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! >INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > ____________________________________________________________ Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail! http://login.mail.lycos.com/r/referral?aid=27005 |