0

I have game based on random generated content. I am using System.Random with specific seed to be able to predict my random outputs. But now I have problem with saving of game, because I need somehow save progress of my System.Random instance to be able to continue with know random outputs after load. Right now Iam saving only seed of my random and creating of new instance of Random will generate same values from begining.

Lets imagin this situation: I will create Random with seed "x" and generate 4 numbers - 84, 68, 12, 98 next I save a game and load again from save and it creates new instance of Random with same seed "x" - this means, that next 4 generated numbers will be 84, 68, 12, 98 again, but i need to continue with sequence and not starting from begining again. Is there any way how to do it elegently, or I need to save some valu that will hold "count" of uses of my Random instance and call Random on my new instance Random instance "count" times?

MrIncognito
  • 153
  • 12
  • 1
    `new Random(yourSeed)` will always generate the same sequence as long as the `yourSeed` int is the same. – FCin Sep 19 '19 at 11:24
  • 1
    Using a seed only makes sense for randomly generated stuff that you want to re-generate the same way some time later. An example for this could be the loading of a randomly generated map in a game from a savegame (i.e. "re-generating" the same map). If you want to have random values after loading, then you should not use any seed for that RNG, so it will provide different values. – bassfader Sep 19 '19 at 11:27
  • Just to be quite clear: You *do* actually want to continue using the same sequence? I.e., it is not an option to just use another algorithm that will actually provide new random values? – Kjartan Sep 19 '19 at 11:32
  • Ok so there is no way how to generate Xth step of random righ away? lets saw I have random instace and i call generate 3 times to get results 56, 87, 64 and next after load i create random and call something like Radom(seed, 3) to get number 64? – MrIncognito Sep 19 '19 at 11:34

0 Answers0