Using multiple random seeds at the same time (SOLVED)

Hello! This is a complicated question, so I’ll try to break it down as well as I can. I’m currently not near needing an answer, but it keeps popping up in my head all the time, and I will need the help at some point, so I might as well already.

I have a game world populated by peeps who go around, go to work, eat, sleep etc. Some of their decisions as well as outcomes of some of their actions are governed by random chance.

What I want is for the player to be able to interact with them (which will obviously also need some random rolls) and when they inevitably die, I want to generate the state the game world would be in if the player never existed. That way you’ll get a measure of how much of an impact you had during the game.

If I simply used the original seed to run the world again (without the player’s input), the outcomes of all random rolls would be affected whenever the player used a random roll himself. Ideally I would use a separate sequence of random values for each of the peeps living in the world, so that their rolls would only change after they encountered either the player or a ripple of his actions in the world.

To make an example:

  • On day 3 a peep called Joe will get hungry and will randomly decide to go to Restaurant A.
  • On day 1 the player has the option to try to intimidate peep called Bill. This shouldn’t affect Joe’s decision on day 3.
  • Bill is intimidated and decides to go to bed to reflect on his life, which means he doesn’t have to make a decision on whether to have one more beer that evening, since he didn’t go to a pub. This also should’t affect Joe two days from then.
  • Due to the change of schedules resulting from this, Bill and Joe meet on day 2 and Joe thinks whether he should talk to him. This extra decision from Joe means he’ll maybe decide to go to Restaurant B on day 3 and that is fine. Joe will be in a slightly different frame of mind on day 3 and thus the butterfly effect can come into play and change the outcome of his decision.

So… this is what I want. I can see some potential solutions here (unless there’s a shortcut I’m missing, which would be awesome):

  1. I can write my own random function that would support what I need. I should point out I have little idea of how I’d go about that. Maybe something like the original Doom used (here) would be enough - the randomness doesn’t have to be too complex.

  2. I can pre-generate all the random numbers I’ll likely need during the game’s course, multiple times, and use those. This sounds needlessly wasteful.

So… any tips on this?

I believe I have seen a few random lua libs out there. One is this one which allows you to create as many random generators as you want with it’s own seed.

I believe it’s what you are looking for :slight_smile:

6 Likes

https://github.com/subsoap/defrng/blob/master/defrng/mt.lua is the one I use most of the time but @andreas.strangequest link seems to be good with many methods included in one!

If you want orders of events to reliably have the same RNG outcome then you want to make the new seed to include a step and the result of an action. It will have a butterfly effect of changing the entire following chance of outcomes vs only including the step number in the seed.

Games with seed based generated dungeons where you can share the seed and people will see the same exact same dungeon use the seed = step generation method. For each step, seed is rest to include the step number so that the next number generated is always the same. What you want is paths where making different decisions impacts all of the following possible events, yes? So you could do seed = step+increment+choice and then save the increment value from the first number generated from that new seed so the incremented value would increase differently based on choices you make but could still come to the same results from two different sets of choices if the RNG values sum up to the same increments.

3 Likes

Either of these should work, thanks!

1 Like