Re: Rand() with base
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 05/21/04
- Next message: Keith Thompson: "Re: Rand() with base"
- Previous message: Mabden: "Re: Rand() with base"
- In reply to: Mabden: "Re: Rand() with base"
- Next in thread: Ben Pfaff: "Re: Rand() with base"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 21 May 2004 16:42:57 -0400 (EDT)
On Fri, 21 May 2004, Mabden wrote:
>
> "Joona I Palaste" <palaste@cc.helsinki.fi> wrote...
> >
> > Does the standard specify that the same seed has to always generate the
> > same sequence of PRNs? But it doesn't specify which seed has to generate
> > which sequence?
Well, obviously, the first seed has to generate the first sequence,
and... :) Yes, 'srand' is supposed to actually seed the PRNG, and 'rand'
is supposed to produce repeatable results. No, the Standard does not
specify which sequences 'rand' must produce --- that would be tantamount
to specifying the 'rand' algorithm, which the Standard doesn't do (and we
all know this because we have all read the FAQ, right? ;)
> I am interested in this as well. I have a game that fills a bag with tiles
> (or it could be a deck of cards, whatever) and I would like to just store a
> (32-bit?) number that would re-generate the exact same sequence. It would
> limit game to have 4billion possible beginnings, but that might just be
> enough. ;-)
The Standard only guarantees 15 bits for RAND_MAX. You want a 32-bit
seed (in conforming C code), you get your own PRNG. Other than that,
yes, 'srand' will help you.
-Arthur
- Next message: Keith Thompson: "Re: Rand() with base"
- Previous message: Mabden: "Re: Rand() with base"
- In reply to: Mabden: "Re: Rand() with base"
- Next in thread: Ben Pfaff: "Re: Rand() with base"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|