How to implement a pseudo-random function
I want to create a sequence of random numbers that will be used to select tiles for the "maze". Each maze will have an ID and I want to use that ID as a seed for a pseudo random function. This way I can create the same maze over and over, given its maze id. Preferably, I don't want to use the built-in pseudo-random function in the language as I have no control over the algorithm and it can change from platform to platform. As such, I would like to know:
- How can I implement my own pseudo-random function?
- Is it even possible to generate platform independent pseudo random numbers?
source to share
Yes it is possible.
Here is an example of such an algorithm (and its use) to generate noise.
These specific random functions (Noise1, Noise2, Noise3, ..) take input parameters and calculate pseudo-random values ββfrom them. Their output range is 0.0 to 1.0.
And there are many others (as mentioned in the comments).
UPDATE 2019
Looking back at this answer, the one below would be a better choice mersenne twister
. Or you can find any implementation xorshift
.
source to share
The Mersenne Twister can be a good choice for this. As you can see from the pseudocode in wikipedia, you can seed the RNG with whatever you prefer to get the same values ββfor any instance with that seed. In your case, the maze id or the hash of the maze id.
source to share