Generate the same 'random' number sequence from a seed

Hi,
I’m trying to generate the same set of ‘random’ numbers, given an initial seed. I’m currently doing the following steps to try to get the same numbers generated each time.

  • Set seed to be a const int by setting `const int seed = 123;`
  • Save the initial state of the number generator on Start() by saving `var state = Random.state;`
  • Set the initial state in my method by calling `Random.state = state;`
  • Specify the same seed each time by calling `Random.InitState(seed);`

Later on I called both Random.Range() & Random.value and expect given the same saved state and same seed that the same values should be generated, but this is not the case.

Does anyone know where I’m going wrong? or any other ways of generating sudo-random number sequences with seeds?

Cheers

No worries, I found the issue. It turns out I was sometimes calling Random.Range() more times than expected, so it was pushing the sequence of ‘random’ numbers out from what was expected.