Hey there! I've been working on an arcade game in SP, and I've come across the need for a random number generator. I figured that I'd build a function for this, so here we are. After some research, I decided to try and implement the linear congruential generator algorithm, which is simple and effective enough for really any use a SP builder may have.
Here it is in action:
And the code--done entirely in variables:
a, c, and m are all parameters involved with the LCG itself. These parameters are just some reference parameters I grabbed from Wikipedia supposedly used on a computer called the ZX81, but they seem to work well enough.
The m parameter inherently limits the max possible value from the raw RNG function, in this case 2^16 - 1. The actual label is slightly processed to be limited between 0 and 100 (by dividing by m and then multiplying 100 as to not hurt the randomness of the number).
The first line of RAND
, doRandom
and setSeed
have to do with setting a seed for the RNG. It is based on the game timer, and it is fixed once you click on the RNG button (or any other "event" to trigger this). Thus, you can pretty much guarantee that you will get effectively completely random numbers from this generator.
This has a lot of uses, so I'm pretty excited! Feel free to play with and modify the RNG generator here.
See you in my next upload!
How would I change the maximum and the minimum amount?
love rng.
best thing that could happen to any sandbox
king 😩
Interesting concept! By the way, I'm wondering what is the range of input for FT? Is it possible to process long integers over 16 digits? And what about the part after the dot? Thanks
"RNG in SimplePlanes doesn't exist, it won't hurt you!"
player: shows this forum post
Jokes aside, this is brilliant! Imagine the possibilities we can do with this!