home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Unsorted BBS Collection
/
thegreatunsorted.tar
/
thegreatunsorted
/
programming
/
misc_programming
/
batnmore.z!p
/
PMMMLCG.BTM
< prev
next >
Wrap
Text File
|
1992-11-15
|
2KB
|
76 lines
*REM This batch file is Freeware, free to use and redistribute unmodified *
*REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
REM Prime Modulus M Multiplicative Linear Congruential Generator
REM Timestamp 15-Nov-1992
REM Modified: return integer 1..limit-1 instead of float 0..1. Still random?
REM Note: this 4dos batch file based on c code by/from...
REM start quote *************************************************************
REM PMMMLCG - Prime Modulus M Multiplicative Linear Congruential Generator
REM Modified version of the Random number generator proposed by
REM Park & Miller in "Random Number Generators: Good Ones Are Hard to Find"
REM CACM October 1988, Vol 31, No. 10
REM - Modifications proposed by Park to provide better statistical
REM properties (i.e. more "random" - less correlation between sets of
REM generated numbers
REM - generator is of the form
REM x = ( x * A) % M
REM - Choice of A & M can radically modify the properties of the generator
REM the current values were chosen after followup work to the original
REM paper mentioned above.
REM - The generator has a period of 2^31 - 1 with numbers generated in the
REM range of 0 < x < M
REM - The generator can run on any machine with a 32-bit integer, without
REM overflow.
REM - This generator is currently running on Sun 3/50, Sparc, IBM PC/XT,
REM IBM RS/6000 just to name a few...
REM
REM John Burton
REM G & A Technical Software, Inc
REM 28 Research Drive
REM Hampton, Va. 23666
REM
REM jcburt@cs.wm.edu
REM jcburt@gatsibm.larc.nasa.gov
REM burton@asdsun.larc.nasa.gov
REM end quote ***************************************************************
setlocal^break on^unalias *
REM Note: originally q = (m / a) and r = (m % a)
set a=48271
set m=2147483647
set q=44488
set m=3399
set seed=2345678901
iff "%1" != "" then
set limit=%1
else
set limit=9999999999
endiff
:loop
set hi=%@int[%@eval[ %seed / %q ]]
set lo=%@eval[ %seed %% %q ]
set seed=%@eval[ %a * %lo - %r * %hi ]
iff %seed gt 0 then
set seed=%@int[%seed]
else
set seed=%@int[%@eval[ %seed + %m ]]
endiff
echo %@eval[ %seed %% %limit ]
goto loop
:end
break off^quit