How do I stop Random.Range generating the same numbers on each Run time play?
I tried placing this at the start of the project.
UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks);
How do I stop Random.Range generating the same numbers on each Run time play?
I tried placing this at the start of the project.
UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks);
It shouldn’t be doing that and it’s not doing that in any of my own tests. By default, Unity always generates a new seed at startup and you should only be using that code there to change it after the fact. What does your Random.Range code look like?
Thanks for the response.
public void PlayNextClip() {
int clipKey = Random.Range(0,MaxKey);
audioSource.clip = BackgroundClips[clipKey];
audioSource.Play();
audioSource.volume = MainVolume;
}
What is your engine version?
Maybe you are affected by UUM-65629 (see How did I break UnityEngine.Random.Range? - #7 by Spy-Master)
Alternatively just use system time as the seed.
So I finally realized this issue only effects playing in Editor. So the actual build it randomizes correctly.