home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / batnmore.z!p / PMMMLCG.BTM < prev    next >
Text File  |  1992-11-15  |  2KB  |  76 lines

  1. *REM This batch file is Freeware, free to use and redistribute unmodified *
  2. *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
  3.  
  4. REM Prime Modulus M Multiplicative Linear Congruential Generator
  5. REM Timestamp 15-Nov-1992
  6.  
  7. REM Modified: return integer 1..limit-1 instead of float 0..1. Still random?
  8. REM Note: this 4dos batch file based on c code by/from...
  9.  
  10. REM start quote *************************************************************
  11.  
  12. REM PMMMLCG - Prime Modulus M Multiplicative Linear Congruential Generator
  13. REM  Modified version of the Random number generator proposed by
  14. REM  Park & Miller in "Random Number Generators: Good Ones Are Hard to Find"
  15. REM  CACM October 1988, Vol 31, No. 10
  16. REM   - Modifications proposed by Park to provide better statistical
  17. REM     properties (i.e. more "random" - less correlation between sets of
  18. REM     generated numbers
  19. REM   - generator is of the form
  20. REM         x = ( x * A) % M
  21. REM   - Choice of A & M can radically modify the properties of the generator
  22. REM     the current values were chosen after followup work to the original
  23. REM     paper mentioned above.
  24. REM   - The generator has a period of 2^31 - 1 with numbers generated in the
  25. REM     range of 0 < x < M
  26. REM   - The generator can run on any machine with a 32-bit integer, without
  27. REM     overflow.
  28. REM   - This generator is currently running on Sun 3/50, Sparc, IBM PC/XT,
  29. REM     IBM RS/6000 just to name a few...
  30. REM
  31. REM    John Burton
  32. REM    G & A Technical Software, Inc
  33. REM    28 Research Drive
  34. REM    Hampton, Va. 23666
  35. REM
  36. REM    jcburt@cs.wm.edu
  37. REM    jcburt@gatsibm.larc.nasa.gov
  38. REM    burton@asdsun.larc.nasa.gov
  39.  
  40. REM end quote ***************************************************************
  41.  
  42. setlocal^break on^unalias *
  43.  
  44. REM Note: originally q = (m / a) and r = (m % a)
  45.  
  46. set a=48271
  47. set m=2147483647
  48. set q=44488
  49. set m=3399
  50.  
  51. set seed=2345678901
  52.  
  53. iff "%1" != "" then
  54.     set limit=%1
  55. else
  56.     set limit=9999999999
  57. endiff
  58.  
  59. :loop
  60. set hi=%@int[%@eval[ %seed  / %q ]]
  61. set lo=%@eval[ %seed %% %q ]
  62. set seed=%@eval[ %a * %lo - %r * %hi ]
  63.  
  64. iff %seed gt 0 then
  65.     set seed=%@int[%seed]
  66. else
  67.     set seed=%@int[%@eval[ %seed + %m ]]
  68. endiff
  69.  
  70. echo %@eval[ %seed %% %limit ]
  71. goto loop
  72.  
  73. :end
  74. break off^quit
  75.  
  76.