home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!rpi!batcomputer!munnari.oz.au!manuel!sserve!hhcs.gov.au!pihlab
- From: pihlab@hhcs.gov.au
- Newsgroups: comp.lang.c
- Subject: Re: Initializing Random Seeds
- Message-ID: <1992Sep7.104159.354@hhcs.gov.au>
- Date: 7 Sep 92 10:41:59 +1000
- References: <1992Sep4.173259.12437@maccs.dcss.mcmaster.ca>
- Organization: Aust. Dept. Health, Housing and Community Services
- Lines: 50
-
- In article <1992Sep4.173259.12437@maccs.dcss.mcmaster.ca>, rickan@maccs.dcss.mcmaster.ca (Mark Rickan) writes:
- > Please excuse me if this is a FAQ, but is there a ANSI-compliant means
- > of initializing a random seed which has a reasonably low probability
- > of recurring? At the moment, I'm using srand in conjunction with
- > time(&t). Unfortunately, on a fast machine, the time delay is often
- > < 1 second, resulting in the production of the same random value.
- >
- > I've avoided this problem by use of a time delay, but I'm convinced
- > that there must be a more elegant and efficient means of doing this.
- >
- > Any suggestions would be appreciated,
-
- I don't write in C but it sounds like you want a random number as a seed.
-
- One way would be to use a random number as part of your seed determination.
-
- Set your MasterSeed1 to some constant value like 123456 or set it based on the
- time when they first log on.
-
- Everytime that you want a new seed:
-
- 1. use your current time sample method to get the time or whatever as a
- SlaveSeed1.
-
- 2. use MasterSeed1 to calculate SlaveSeed2.
-
- 3. set MasterSeed1 to value of SlaveSeed2 for next cycle.
-
- 4. Apply some function to SlaveSeed1 and SlaveSeed2 to give SEED.
-
- 5. Use SEED to generate your RANDOM NUMBERS.
-
- The function in step 4 could be ADD, MULTIPLY, SUBTRACT, OR, AND, XOR or
- whatever works for you. (Interested in seeing your final implementation)
-
- If that still gives you numbers close together or closely related to the
- MasterSeed sequence then simply factor in MasterSeed2 and alternate between
- using MasterSeed1 and MasterSeed2 etc.
-
- --
-
- Bruce... pihlab@hhcs.gov.au
- ^^
- *******************************************************************
- * Bruce Pihlamae -- Database Administration *
- * Commonwealth Department of Health, Housing & Community Services *
- * Canberra, Australia (W) 06-289-7056 *
- *******************************************************************
- * These are my own thoughts and opinions, few that I have. *
- *******************************************************************
-