algorithmassemblyprng

Pseudorandom generator in Assembly Language


I need a pseudorandom number generator algorithm for a assembler program assigned in a course, and I would prefer a simple algorithm. However, I cannot use an external library.

What is a good, simple pseudorandom number generator algorithm for assembly?


Solution

  • Easy one is to just choose two big relative primes a and b, then keep multiplying your random number by a and adding b. Use the modulo operator to keep the low bits as your random number and keep the full value for the next iteration.

    This algorithm is known as the linear congruential generator.