# How do I generate persistant float values from a random seed?

I have a random seed. I want to generate a float between 0 and 1 from that seed. How do I do this in unity to make sure I get persistent results when using the same seed again, yet different seeds return completely different results, like you would expect?

I believe it has something to do with bitwise operators or something? I am not very familiar with this, can you help shed some light on this for me?

Thanks.

Random.seed = 1;
print (Random.value);
print (Random.value);
Random.seed = 2;
print (Random.value);
print (Random.value);
Random.seed = 1;
print (Random.value);
print (Random.value);

I've just tested Unity's pseudo-random-generator and it works as expected. Just set your integer seed with Random.seed and then use Random.value to get your float values. Keep in mind that any call to Random.Range or any query of Random.rotation, Random.onUnitSphere, Random.insideUnitCircle, Random.insideUnitSphere, Random.value will continue the pseudo number chain.

Also keep in mind that like in all compiler / language descriptions mentioned they could change the random generator implementation at any time so it could be possible that in future relases it will produce a different set of numbers.

If it's very important that the sequence stays the same you have to implement your own pseudo number generator. One of the simplest is a linear congruential generator. Since i grown up with Pascal / Delphi i'm used to borlands implementation ;)

Interesting. i used a modulo system for pseudorandom numbers previously.

``````seed = 1;
random number 1 = (seed * 314.15144)%1
random number 2 = (seed * 223.60613)%1
etc up to random number 20
``````

etc. it’s not that random because it’s quite periodic. but it’s a good start for coding. also you can slowly change the seed and the random numbers will slightly vary, so creating controllable mods of a setting that you like. that said I want something similar and yet better.

I always want a random seed that can generate 10 20 random numbers for complex presets on things, terrain, patterns, etc, so i guess you could set Random.seed and then generate 20 rand values and set them as variables. Although if you get a nice setting and you want to find mods of it, Random.seed is Integer and you can’t generate similar values as with perlin noise etc.

perhaps perlin noise in unity is largely fine for controllable rand nums also.