How to incremement a random stream?

I’m using a seed to pull locations for actors to spawn at, and I increment it every iteration of the for loop.

I use this seed to determine the location and actor type from an array, but since the seed increment by just 1, the location and the switch on int seem to as well?

I was under the impression seeds were entirely random? How would it always be incrementing 1 if it uses a new “pattern” every seed? I’m breaking the seed the player sets, incrementing that int and using that to make a new seed which then decides random int values in a range. But since it just increments I get the same actors down the array list.

That is all connected up I just moved them off it for the screenshot.

Any help appreciated, thanc.

The whole point of a seed, is you use it only once.

So set the seed to 42, for instance and then keep calling ‘randdom int in range from stream’.

Next time you run the game, you can change it from 42 to 1.8, if you like, and you will get an entirely different stream.

So I could do this:

It will give me the same 10 numbers every time I run it.

If I want different number, I have to set the stream with a different seed. The point of streams is they are repeatable.

If you want to be surprised every time, then just use:

Yeah I understand that, but say I want the stream to decide the same location for multiple actors. How would I do that? If I use the same stream over and over again it will plop all actors in the same spot, since it pulls the same number.

But say I got an array of actors and I use a loop to generate a random int to say which actor to pull from array. In that loop, it will just reuse the same int once it is decided by the stream, I attempted to solve this with an increment int on the stream and then use that for the next number but it just increments down the array for some reason?

2nd picture is what you want to pull randomly from an array.

But I want the randomness to be predictable from the base stream. If player 1 finds a cool room in the dungeon, I want them to be able to share the dungeon seed for other players. If I use a random with no stream it will never generate the same again.

There are only two options.

  1. Predictable random ( pic 1 ). The seed sets up the stream ( but you can’t change the seed ).

  2. Unpredictable random ( pic 2 ).

If player 1 finds a good stream, they can just share the seed with other players.

But the stream always outputs the same number.

Let’s say I have an array of 5 actors, and a for loop that will spawn them in. The amount of actors, location and which actors are all based on the seed and decided in this loop. The player sets the seed to 0.

Stream 0 picks 2 for the first actor to spawn, and then it just repeatedly picks 2 everytime.

I attempted to solve this by making every iteration of my loop increment the random stream the player sets by 1. Since the stream is different surely the next number it chooses would be random. But it also increments the number it picks.

So then stream 0 picks 2 for the first actor, the loop increments the stream and then the new stream of 1 picks 3, the loop increments the stream and then the new stream of 2 picks 4, repeat.

Since the stream is different shouldn’t what it picks be different? I need the stream to give me a predictable random actor spawn loop.

It seems that if you use “pass by reference” on the random stream input on your functions it will actually create a random predictable set of numbers that is different per stream.

Keeping this up for posterity as it took me a couple solid hours of googling to find that nugget of info, cheers!

2 Likes