top of page
Writer's pictureKane Adams

Pseudo-Random Numbers

Updated: Nov 14, 2022

This week focused on how random numbers are generated with the task given out being an attempt at implementing two types of Random number generators, "Linear Congruential Generator" and "Mersenne Twister". Like the previous week, I created one without following a tutorial and one where I did.


Linear Congruential Generator

Also referred to as the Lehmer RNG (Random Number Generator), this generator was made without following a tutorial but by researching what the mathematical formula is.


Linear Congruential Generator formula

For this implementation, I created it within Unity so that a random number is generated when I clicked a button where the input is taken by the current date and time as ticks. It then multiplies by a, added to by the increment (c) and then that result is divided by the modulus (m) with the value being the remainder.

I furthered this by having the user able to give a minimum and maximum value (with the maximum being excluded, inspired by Unity's Random.Range function). This will have the equation repeat until it is within those ranges. The minimum was originally added because at one point I ended up with negative numbers, however, I have not had it happen since and this parameter now acts as an extra precaution to reduce any errors.


Mersenne Twister

I completed the Lehmer generator quickly, leaving me with most of the week's research on the Mersenne Twister. However, my understanding of the twister is very minimal as it is a lot more complex and involves bit manipulation. I eventually resorted to following a tutorial very closely. I will not be using the Mersenne Twister in my final assignment.



Plans moving forward

After this week, I am interested in adding the Linear Congruential Generator to my final assignment and will put in the time to turn it into a C# tool that I can use in all projects.

6 views0 comments

Recent Posts

See All

Comments


bottom of page