-
August 31st, 2013, 01:31 PM
#1
how reliable is rand() ?
how reliable is rand() ?
I want to make a statistic info gathering program, I want it to run millions (perhaps billions) of random scenario's
and record the percentages/averages, yes I know I could do it mathematically quite easily in most cases, but in other cases it's easier just to run a simulation (especially if you need a fair amount of data)
would rand() be good for this? or does rand() loop after a while? and if so, after how many digits?
-
August 31st, 2013, 02:15 PM
#2
Re: how reliable is rand() ?
The exact algorithm used for rand depends on the standard library implementation. In your case, you might want to use an algorithm with known characteristics, e.g., some version of Mersenne Twister, which is available in the C++11 standard library via the <random> header.
-
September 2nd, 2013, 06:47 AM
#3
Re: how reliable is rand() ?
you ask the wrong question.
rand() is very reliable.
it is however unsuitable for just about anything. It's period is too short (typically 32k although some exceptions exist), and the number of bits it has is too few (again, typically 15 bits).
For "real" work you need a PRNG that generates over a longer period and has more bits. Note that all PRNG's end up generating "predictable" patterns that may show up as artefacts depending on how they're being used.
Some applications need "more randomness", while others need "higher period" and still others need "crytographically secure", and some prefer (or prefer against) uniformity (yes, as odd as that may seem).
if you're "unsure" and just want "as random as possible", a 32bit mersenne twister will probably be a good place to start. 32bit MT will probably be sufficient, but I've worked on a project that needed a 128bit MT so unless you can provide more info on your needs, it's impossible to give solid advice.
You' question is formulated strange in that sense. do you need millions of generated random numbers. or do you need millions (bilions) of different random number sequences.
the one is a matter of periodicity, the 2Nd is a matter of seeding (and choice of algorithm).
Last edited by OReubens; September 2nd, 2013 at 06:51 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|