home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!eliot!andyc
- From: andyc@eliot.uucp (Andy Panda Collins)
- Subject: Re: Any simple Random Number generators?
- Message-ID: <1992Aug18.183949.23541@eliot.uucp>
- Keywords: random bit stream
- Sender: andyc@eliot (Andy Panda Collins)
- Organization: Systems Center, Inc., Reston, VA, USA
- References: <13AUG199218224504@judy.uh.edu> <1992Aug14.104121.29374@corax.udac.uu.se> <dak.713874609@kaa>
- Distribution: na
- Date: Tue, 18 Aug 1992 18:39:49 GMT
- Lines: 44
-
- >>In article <13AUG199218224504@judy.uh.edu> cscc13@judy.uh.edu (NAVEED IQBAL) >writes:
- >
- >>>I want to know how random numbers are generated.
- >Well, suggesting that you save your last number, in 32bit unsigned systems
- >you can get good 32-bit numbers by multiplying the last value with 69069
- >and adding 1. This pretty good, easy to memorize number generator is ana-
- >lyzed in The Art of Computer programming vol. 2.
- >
- >You have to use the higher bits when wanting a small random number, or the
- >behaviour will be terrible. That is, use ((long long)rand * 25 >>32) for
- >a number from 0 to 24.
-
- This ^^ method sure is simple. Here is an alternate method for generating
- random bits, may I repeat, RANDOM BIT STREAMS. The word that is used can't
- be considered random by any definition, really. Anyway here's the method
-
- This method is best suited for electronics buffs, but is applicable to
- computers as well.
-
- Take a n-bit shift register and a couple of XOR gates and put together
- a circuit like the following.
-
- +---+---+---+---+---+--- ---+---+---+---+---+---+
- | | | | | | ... | | | | | |
- <---- 1 | 0 | 1 | 0 | 1 | ... | 0 | 1 | 0 | 0 | 1 ---+
- +-|-+---+---+---+-|-+--- ---+---+---+---+---+---+ |
- | | __ |
- | +-------------\\ \ |
- | || >-----------------+
- +-----------------------------//__/
-
- As the shift register shifts the XOR gate will take inputs from the
- shift register and put its output as the registers input.
-
- This method is now clearly better suited for hardware applications,
- but can be implemented in software.
-
- For rmore information about this and the theory of its operation
- look into some discrete math books or even Numerical Recipes books,
- that's were I remember seeing this in the first place.
-
- Andy Collins
-
- andyc!eliot!uunet
-