Random.seed changing in the following code

Hey!

So I did something similar to this code before, but now in the following code, the seed changes every call.

Tested with Debug.Log:

 public static T [] RandomizeArrayWithSeed <T> (T [] array, int seed) {	
		Random.seed = seed;
		for (int i = 0; i < array.Length; i ++)
		{
			int randomIndex = Random.Range (i, array.Length);
			T tmp = array [randomIndex];
			array [randomIndex] = array *;*

_ array = tmp;_
* }*
* return array;*
* }*
I hope this can get sorted out. Thanks!

It’s not really clear what you mean, but if you’re reading Random.seed after calling the function, then yes, it won’t be the same as what you passed in. Otherwise it wouldn’t work…if Random.seed stayed the same, then Random.Range would return the same number every single time.

of course it would change every call, you are reassigning it every call with Random.seed = seed; If you want the seed to not change, setup it up outside of the function once and reuse it.
oh I think I see what you are trying… hmm…
you want Random.Range to recall the same thing every time you put in the same seed?? Because that’s not how Random.Range works. I believe it weighs the seed against the system clock.

using
void Update () { Random.seed = 10; Debug.Log(Random.seed.ToString ()); }
it’s obivous the seed doesn’t change on it’s own randomly, but things that use the seed will still change based on other variables

I usually use System.Random for my random numbers. I usually use a string for a seed. Then I have a bool useRandomSeed and if useRandomSeed is true then I do something like seed = DateTime.Now.ToString(); and if you want to use the same seed then you would do something like Random random = new Random(seed.GetHashCode());

I’ll accept @Eric5h5 but I want to say what happened in an answer.

I had this Map Generator script using that static class’ void, but since the Map Generator script had an issue, even though it was completely irrelevant, it caused the randomizer to break.