Re: rand - is RAND_MAX how long before the same # will occur again?
From: pete (pfiland_at_mindspring.com)
Date: 02/05/05
- Next message: Douglas A. Gwyn: "Re: is NULL-checking redundant in accessor-functions?"
- Previous message: Gordon Burditt: "Re: is NULL-checking redundant in accessor-functions?"
- In reply to: Keith Thompson: "Re: rand - is RAND_MAX how long before the same # will occur again?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Douglas A. Gwyn: "Re: is NULL-checking redundant in accessor-functions?"
- Previous message: Gordon Burditt: "Re: is NULL-checking redundant in accessor-functions?"
- In reply to: Keith Thompson: "Re: rand - is RAND_MAX how long before the same # will occur again?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|