Archived

This topic is now archived and is closed to further replies.

Random number generator in VC++

This topic is 5530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites