home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8580 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  1.9 KB

  1. Path: sparky!uunet!bonnie.concordia.ca!hobbit.ireq.hydro.qc.ca!beaurega
  2. From: beaurega@ireq.hydro.qc.ca (Denis Beauregard)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: Random numbers in assembly language
  5. Message-ID: <Bt55GE.8t9@ireq.hydro.qc.ca>
  6. Date: 17 Aug 92 18:45:50 GMT
  7. References: <92220.125612F13@psuvm.psu.edu>
  8. Sender: news@ireq.hydro.qc.ca (Netnews Admin)
  9. Organization: Institut de recherche d'Hydro-Quebec, Varennes, Canada
  10. Lines: 36
  11.  
  12. I don't see how you could generate random numbers using a timer, except
  13. for the 1st number ;-)
  14.  
  15. So, another solution :
  16.  
  17. From Electronics, May 27, 1976.
  18.  
  19. You will have to consider a word or a byte and a few bits (or taps) in it.
  20. You shift the word and insert a value (i.e. carry) that is one or zero
  21. depending on the added value of the taps (with a xor operator).
  22.  
  23. carry = A xor B xor C, when A, B and C etc. are taps.
  24.  
  25. For the longer sequence, with one byte, use:
  26. bits 1 and 7 or 3 and 7 (i.e. carry depends on bits 1 and 7, then do a ROT).
  27.  
  28. For a word (15 bits in the example), you will get 32767 consecutive different
  29. pseudo-random values from : 1 and 15, or 4 and 15 or 7 and 15.
  30.  
  31. For a double word (31 bits), taps are 3 and 31, 6 and 31, 7 and 31 or
  32. 13 and 31 (2,146,483,647 values).
  33.  
  34. For the exact programming, I leave it to the original poster!  After all,
  35. you selected Assembly because it was too easy otherwise...
  36.  
  37. P.S.  I used taps because the original article is for an electronics device.
  38. Taps are selected bits.
  39.  
  40. P.P.S.  You still select the initial value from a true random event like
  41. the initial clock value, but don't use the 18.2 clock (not enough random).
  42.  
  43. -- 
  44.   \_\    Denis Beauregard  *  internet:beaurega@ireq.hydro.qc.ca
  45.  /   \   Genealogiste officiel : Beauregard/Jarret/Jarest/Vincent
  46. J   __>  Barthelemy Jarret (1471) -> Andre Jarret, sieur de Beauregard (1665)
  47. \_.-===   -> Denis Beauregard (1992)                  Opinions ? Et pis non !
  48.