I'm sorry, I'm still new to assembler. I thought your answer was pretty enlightening, but what does "mon" do?

Leron

Quote:

> mon edx,0 > div eax,esi > mov [RVal],eax > retn

Tue, 10 Jul 2001 03:00:00 GMT

Kevin G. Rhoad#4 / 10

Random ?

The choice of multipliers in linear congruential pseudo-random generators is far more advanced than just "use a prime". Knuth's volume 2, Seminumerical Algorithms, devotes a lot of pages to this. Table 1 lists several generators, mostly good, but with one or two "bad" examples. Borrow a copy, use one of the good ones.

Also, mod 1601, even with an excellent multiplier will give a poor pseudo-random stream because the modulus is WAY too low.

Note that many of the generators in Knuth's Table 1 have moduli of (2^n)-1 or (2^n)+1. For either of these cases assembly implementation is trivial if n=word width. For a n-bit by n-bit multiplication, the high n bits of the 2n-bit result are either added to or subtracted from the low n bits. This kind of operation, while difficult to implement efficiently in most HLLs, is trivial in assembly.

I would recommend choosing one of the table entries with 2^32 +/- 1. Smaller moduli are asking for trouble.

Not all combinations of primes work for these 'linear congruential generators'. This will repeat every 1601 calls, you may want to hunt a generator with a longer cycle. (do a web-search for linear congruential random number generator' perhaps?)

If you find the source code to the rand() C runtime library function (and there are several on the net) then you can translate that to assembly. Most are linear congruential. I know Borland (used to) supply the source to their CRTL.

Also search for 'Linear Feedback Shift Register', which is a very quick way of giving a single random bit.

> Not all combinations of primes work for these 'linear congruential > generators'. > This will repeat every 1601 calls, you may want to hunt a generator > with a longer cycle. (do a web-search for linear congruential random > number generator' perhaps?)