How do you generate a random number in Assembly language using the FASM compiler? -


Hey guys, I'm really new to the assembly and I'm trying to create a simple program. For this, I need to generate a random number.

Nobody knows how I can do this with the FASM compiler?

Thanks, Sam

You can use a linear-rich algorithm . Its most common psuedo-random number algorithm.

Basically, you have a seed value. And once again when you generate random numbers, each number becomes a seed for a new request.

numbers

x = (a * s + b) MOD M

where A, A and B are chosen for algorithms is. Some popular sets of these values ​​are used. It is very easy if you make power of 2, especially for 32 bit machines 2 ^ 32 then the modern step is done automatically by the machine.

Look at Wikipedia, they have popular sets of A, B and M and a lot more information.

There are more complex things can also be done with seeds (for example, establishment of seeds based on present time)


Comments