[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Part1 - Part2 - Part3 - Single Page
Top Document: x86 Assembly Language FAQ - General Part 3/3
Previous Document: 31. Other FAQs
Next Document: 33. Command Line Arguments
-
Search the FAQ Archives
Part1 - Part2 - Part3 - Single Page
Top Document: x86 Assembly Language FAQ - General Part 3/3
Previous Document: 31. Other FAQs
Next Document: 33. Command Line Arguments
32. Pseudo Random Number Generator in Assembly Language
Mark Adler wrote a set or pseudo random number generators based upon
algorithms from Knuth's "Art of Computer Programming", vol 2, 2nd ed.
The file comes with full assembly source and .obj files for all major
memory models. While written to link with Turbo C, the .obj files when
linked with Microsoft C worked well, except for the procedure that
return a double random number. The reason was that the return protocol
is different between Borland C and Microsoft C. Once the code was
modified to work with Microsoft C, the code worked well.
To test the algorithms, I created an array of 100 random numbers and
then generated random numbers and tried to determine if the original
pattern was ever repeated. My program kept the length of the longest
matching series. For real or double, the longest matching series was
one after more than a billion random numbers. For ints, 0 and 1 as the
only selections produced the longest matching series of 31 matches after
more than a billion random numbers. Increasing the range of acceptable
numbers quickly reduced the longest matching series to 2 in over 250
million random numbers. My short testing revealed that the longest
matching series seldom increased after this number.
Lastly, to test the distribution, I counted the number of hits for each
number between 0 and 100. I collected about 100,000 hits for each
number. The standard deviation was only 319 or less than 0.33%.
While my testing was not a rigorous mathematical testing of the
algorithm and its implementation, I believe for most uses, these
procedures are adequate.
The file is available:
ftp://ftp.simtel.net/pub/simtelnet/msdos/turbo_c/tcrnd11.zip
Note that the description of this file is inaccurate.
Contributor: Raymond Moon, raymoon@moonware.dgsys.com
Last changed: 4 May 96
Top Document: x86 Assembly Language FAQ - General Part 3/3
Previous Document: 31. Other FAQs
Next Document: 33. Command Line Arguments
Part1 - Part2 - Part3 - Single Page
[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Send corrections/additions to the FAQ Maintainer:
raymoon@moonware.dgsys.com
Last Update October 22 2009 @ 05:22 AM