Random number generator in VC++

Started by
3 comments, last by kirkd 21 years, 5 months ago
I''m working on an application which requires a lot of random number generation. There''s a little bug that seems to crop up based on the number generated, so I''ve decided to step into Debug mode to find it. The idea is I run in Release mode and store the random number in a file until the bug occurs. Then switch to Debug mode and use the specific random number to force the bug to pop up. It''s much faster than waiting for Debug mode - sssssslllllllooooooowwwwww. But, what I''ve found, is that the series of random numbers is different between the two modes! Now, I''ve created a tiny application which just writes out random numbers and it seems to be fine between the two modes. Any ideas on why I''m getting different series??? -Kirk
Advertisement
How are you seeding the random number generation.

If it''s time based, it''s totally possible that the time taken to start the program in Debug builds is longer than that in Release.

A better way for debugging purposes would be to fix the seed to the same value for both.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Boost.org has many interesting random-number generators, with various performance characteristics. If you''re still working on GAs/GPs, and this is a bottle-neck, you should definitely check them out. Much more flexible than rand().

Cédric
Thanks for the replies and sorry for the long time to respond.

Regarding seeding, I''m using a specific number to seed the random number generator in both Debug and Release modes. In general, this problem is not necessarily a bottleneck but more of an oddity.

-Kirk

Could it be that you''re calling rand () a different number of times in the two modes? Might there be a call to rand () inside an assert statement, or something else that gets compiled-out?

This topic is closed to new replies.

Advertisement