Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 990
TCJ Avatar asked Sep 18 '08 05:09

TCJ


People also ask

What is pseudorandom bit generator?

A deterministic algorithm which, given a truly random binary sequence of length k, outputs a binary sequence of length l >> k which appears to be random. The input to the generator is called the seed, while the output is called a pseudorandom bit sequence. Source(s):

How do pseudorandom generators work?

Instead they rely on algorithms to mimic the selection of a value to approximate true randomness. Pseudo random number generators work with the user setting the distribution, or scope from which the random number is selected (e.g. lowest to highest), and the number is instantly presented.

Does random () Generate random or pseudorandom values?

random — Generate pseudo-random numbers — Python 3.11.0 documentation.


2 Answers

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.

like image 66
jjrv Avatar answered Sep 17 '22 08:09

jjrv


Volume 2 of The Art of Computer Programming has a lot of information about pseudorandom number generation. The algorithms are demonstrated in assembler, so you can see for yourself which are simplest in assembler.

If you can link to an external library or object file, though, that would be your best bet. Then you could link to, e.g., Mersenne Twister.

Note that most pseudorandom number generators are not safe for cryptography, so if you need secure random number generation, you need to look beyond the basic algorithms (and probably should tap into OS-specific crypto APIs).

like image 26
Derek Park Avatar answered Sep 17 '22 08:09

Derek Park