Re: Way for computing random primes in standard C.
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Tue, 28 Feb 2006 00:55:34 GMT
"Rod Pemberton" <do_not_have@xxxxxxxxxxxxxxxxxxx> writes:
"Keith Thompson" <kst-u@xxxxxxx> wrote in message[...]
news:lnzmkefzv3.fsf@xxxxxxxxxxxxxxxxxx
So you're asserting that repeatedly calling srand() improves the<snip>
randomness of the numbers returned by rand()? In particular, you're
claming that that something like this:
is likely to yield better (more random) results than if the second
call to srand() were removed (perhaps with a different number of
calls)?
KEITH: NO! Completely incorrect! This is the fifth time and last time.
Since I'm tied of trying to get through to you, I'll just repeat what I
posted to Sinaur. If you don't comprehend, you can deal with your
inabilities in private.
"As I've stated previously, the randomness is in the non-perfect algorithm
in rand(). But, the set of numbers generated by rand() is affected by
srand(). srand() doesn't affect the randomness of values that rand()
generates, it only changes the set of generated numbers. Since the
algorithm isn't a perfect-random number generator but a pseudo-random number
generator, the probabilities of certain numbers occurring is higher than
others. These probabilities can be shifted by calls to srand(). "
The fact that rand() is a pseudo-random number generator does not
imply that certain numbers appear with a higher probability than
others. For example, if RAND_MAX==32767, it's entirely possible that
each of the 32768 possible values will appear with exactly equal
probability over the long run, for each possible seed. (The generator
can still be imperfectly random even if this is true. For example,
rand() is likely to repeat over a cycle whose length depends on the
size of its internal state; a true random number generator would not
do so, though over the very long run it will sometimes appear to do
so.)
Or have I misunderstood what you meant by "the probabilities of
certain numbers occurring is higher than others"?
In your initial contribution to this thread, you wrote:
] The algorithm which generates a semi-random or pseudo-random number
] sequence has some internal initial values. If you don't call
] srand(), the sequence will be semi-random but will be the same
] sequence every time you run your program. So, if you were to write
] a card playing program, you might call srand() at every shuffle to
] start a new semi-random sequence and call rand() to generate the
] deck of cards. The "randomness" comes from the algorithm in rand()
] not from the starting values in generated by srand().
My response was that it would make more sense to call, say,
srand(time(NULL)) exactly once at program startup, and use successive
values from the *same* pseudo-random sequence for successive shuffles.
You said I was wrong.
You seem to be claiming that calling srand() *again* for each shuffle
is somehow better than calling srand() exactly once at program startup
and generating all shuffles from the single resulting pseudo-random
sequence. (By "calling srand()", I mean "calling the srand function
with some appropriate argument, such as srand(time(NULL))".) Is that
in fact what you've been claiming? In what sense is calling srand()
repeatedly better than calling it only once? How is starting a new
pseudo-random sequence better than continuing to use the original one?
Note that inserting an extra call to rand() will also change the
behavior of subsequent calls to rand(); would that suit your purpose
as well?
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: Way for computing random primes in standard C.
- From: Nelu
- Re: Way for computing random primes in standard C.
- From: Nelu
- Re: Way for computing random primes in standard C.
- From: Micah Cowan
- Re: Way for computing random primes in standard C.
- References:
- Way for computing random primes in standard C.
- From: fieldfallow
- Re: Way for computing random primes in standard C.
- From: Rod Pemberton
- Re: Way for computing random primes in standard C.
- From: Keith Thompson
- Re: Way for computing random primes in standard C.
- From: Rod Pemberton
- Re: Way for computing random primes in standard C.
- From: Keith Thompson
- Re: Way for computing random primes in standard C.
- From: Rod Pemberton
- Re: Way for computing random primes in standard C.
- From: A. Sinan Unur
- Re: Way for computing random primes in standard C.
- From: Rod Pemberton
- Re: Way for computing random primes in standard C.
- From: Keith Thompson
- Re: Way for computing random primes in standard C.
- From: Rod Pemberton
- Way for computing random primes in standard C.
- Prev by Date: malloc behavior on failure
- Next by Date: Re: trying to make my "fillvalues" function work...
- Previous by thread: Re: Way for computing random primes in standard C.
- Next by thread: Re: Way for computing random primes in standard C.
- Index(es):
Relevant Pages
|
|