Advertisement

fast random number generator

Started by January 04, 2003 08:09 AM
0 comments, last by Knuffelbert 21 years, 10 months ago
I posted the same thing a opic below, but most won''t read it since it''s allready answerd very well... I know how i can get random numbers, the problem is that i need a couple thousand random numbers within a very short time, since the "TIME" is in seconds and therefor changes only each second. But my PC is fast enough to produce those thousands of numbers usually within 1 second, ergo all the random numbers are the same.... Tried to seed with srand(time(NULL)+i) (i is a loopvariable, since it will increase every tiome with one, the seed should be increased by one, and since the random number is calculated in way so the seed number 51 could produce say 20 and seednumber 52 1423 for example) Unfortunatly that doesn''t work a intented, i still get allways the same numbers Any ideas? excuse my english...it''s not my mother tongue..
Do not reseed the RNG. You only need to do that once, at program startup, then call rand() as many times as needed.

This link provides a selection of PRNGs

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement