Re: rand - is RAND_MAX how long before the same # will occur again?

From: pete (pfiland_at_mindspring.com)
Date: 02/05/05


Date: Sat, 05 Feb 2005 07:03:43 GMT

Keith Thompson wrote:
>
> pete <pfiland@mindspring.com> writes:
> > Eric Sosman wrote:
> >
> >> It is
> >> certainly an error to assume that rand() will not repeat itself
> >> within RAND_MAX calls; it is even possible that two rand() calls
> >> in a row can return the same value.
> >
> > It is even possible that *all* rand() calls can return the same value.
>
> C99 7.20.2p2:
>
> The rand function computes a sequence of pseudo-random integers in
> the range 0 to RAND_MAX.
>
> I don't think you can stretch the meaning of "pseudo-random" to
> include a repeated sequence of the same value.
>
> (On the other hand, if it generated truly random values, there would
> be a finite probability that it could produce an arbitrarily long
> sequence of a single value.)

It's a quality of implementation issue,
like a malloc that always returns NULL.
There's nothing in the standard which prohibits
a very poor quality rand().

-- 
pete


Relevant Pages

  • Re: Random number help
    ... >> I need your guidelines about Random number ... >> RAND function in Matlab.As in my problem it is giving me same ... >> sequence of values in each iteration of the for loop. ... In other words, take it out of your FOR loop, if not out of your code ...
    (comp.soft-sys.matlab)
  • Re: random is not random enough?
    ... > stop the program and re-run it, the same sequence is produced. ... That is that under the hood this random calls srand once and then calls ... rand after that. ... The rand function is a pseudo random generator. ...
    (comp.lang.c)
  • Random number help
    ... generation as I am unable to figure out the right technique to use ... RAND function in Matlab.As in my problem it is giving me same ... sequence of values in each iteration of the for loop. ... Nishant ...
    (comp.soft-sys.matlab)
  • Help for random number generator
    ... number generation as I am unable to figure out the right technique to ... RAND function in Matlab.As in my problem it is giving me same ... sequence of values in each iteration of the for loop. ... Nishant ...
    (sci.stat.math)
  • Help for random number generator
    ... number generation as I am unable to figure out the right technique to ... RAND function in Matlab.As in my problem it is giving me same ... sequence of values in each iteration of the for loop. ... Nishant ...
    (sci.stat.math)