home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / programm / 2372 < prev    next >
Encoding:
Text File  |  1992-08-18  |  2.4 KB  |  58 lines

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