- Home /
Random.seed Repeating
Does anyone know why I might be getting repeating values by setting Random.seed
. Even if I use a prime number I get a mirror effect. I'm not even multiplying it my anything:
Random.seed = 3;
int value = Mathf.RoundToInt(Random.Range(-10, 11));
This essentially is called again for every block the world, returning value
(see picture below):
![alt text][1]
What might be causing this? [1]: /storage/temp/6122-img.png
Well Random is just a function that is suppose to give you random numbers. In this case you seem to get undesireable graph. Nothing is limiting you though, to search for a Random class online and get what you need.
Why do you need Random.seed? Are you needing to make something that is random, yet reproduceable later?
It's not clear how you use the random generator. If you set the seed manually to a fix number you will always get the same sequence of numbers. True randomness isn't possible since it's a pseudo-random-generator. That's why the seed is usually initialized with the current date / time. That ensures that each time you start your application you get a different sequence.
Again, show and tell us how you actually want to use the generator.
Answer by Dave-Carlile · Dec 27, 2012 at 08:12 PM
Each time you set Random.seed the generator gets reset. So if you're setting the seed in Update, then grabbing a random number, you'll always get the same value. Set the seed in Awake or Startup instead.
Oh i didnt even notice he is setting the seed every time. This is your answer.
Yep, this fixes it. Thanks and sorry for not being more specific.
Answer by Eric5h5 · Dec 27, 2012 at 08:15 PM
You need to post more code; it's not clear what you're doing. This produces no mirror effect:
Random.seed = 3;
for (var i = 0; i < 300; i++) {
Instantiate (prefab, new Vector3(i, Random.Range(-10, 11), 10), Quaternion.identity);
}
Also you don't need Mathf.RoundToInt, since Random.Range when used with integers already returns an integer.