|
From: Per W. <pw...@ia...> - 2004-11-09 14:41:38
|
I would assume your first rand() call always produces the same result, i.e. that you seed the random number generator with a constant multiplied with the current time. No much differene from the all-time "favorite" of using process PID multiplied with time(). A large number of applications have done this for generating session keys or similar. A short analysis makes this approach obvious and an attacker may then find out a very small range of possible seed values when trying to recreate the random sequence used. Don't forget that most of the programs in the world are built using a small set of runtime libraries. The runtime libraries are created using an even smaller set of standard pseudo-random number generators. When just generating some semirandomnes for "fun" in an application, this doesn't much matter. However, as soon as the random sequences are used for some soft of security, the seed becomes very important, and it might also be an idea to think about the sequence, since max 2^32 sequences may be created, which is very easily scanned. /Per W On Tue, 9 Nov 2004, Aitor Moreno wrote: > > If you test the code, you will get values between 0 and 99, i.e. a lack of > > samples with value 100. > > In fact, like I use real numbers, the achieved numbers are between 0 > and 99.9999999999... > analytically.. the number is in the range [0..100) It can be 0 but no 100. > > In this situation, an int truncation must be performed ... > > > > > using the time() of the application start as seed is very dangerous, which > > Netscape knows about... > > I allways use this instruction: > srand( (unsigned)time( NULL ) *rand()/RAND_MAX ); > > With this, a random number is used to seed the next random number... > it is more reliable. > > Bye! > > > -- > Aitor Moreno > ait...@gm... > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Sybase ASE Linux Express Edition - download now for FREE > LinuxWorld Reader's Choice Award Winner for best database on Linux. > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |