- Home /
Random.Range is the same in each object with the script
So I have this problem where every object that has this one script on it produces the same exact random numbers when Random.Range is called. I know I can use Random.initState to change it so its not the same random numbers every time i press play, which is working, but I now have a problem where if there is 10 objects that are all spawned at the same time, they will all get the exact same random number when Random.Range is called. is there any way that I can make each on have a completely different Random number even though they all have the exact same script on them?
@Vice_Versa give the script you write, include Random.initState() line
I dont have it atm, its on someone elses computer. But im calling it in the Start Function like this void Start() { Random.initState(System.DateTime.Now.$$anonymous$$illisecond; }
There's your problem, things happen so fast (think, microseconds) that they all get seeded with the same inital time.
Ins$$anonymous$$d, you can get psuedorandom seeds by seeding them with another random number generator. $$anonymous$$ost PRNGs are so chaotic that even seeding them with sequential numbers will give you totally different internal states.
Functionally, what I'm saying is that each object can have something like
public int prngSeed;
private void Start()
{
Random.InitState(prngSeed);
// ...
and when you instantiate the object, you set prngSeed = Random.Range(0, 999999999)
or similar
Your answer
Follow this Question
Related Questions
How can I randomly create a number and then delete it to stop repeating 3 Answers
Why aren't my random numbers random? 1 Answer
Random String from list of string without repeated letters 2 Answers
Calling 2 specific random float numbers in random.range using array not working! 2 Answers
How to make enemy prefab spawn at random times between 1.0f to 10.0f. 1 Answer