Download

Random Stream giving same output during loop

So I have a Random Stream which is given a random stream, and I pass it around the various functions, but when I get to a For Loop which is meant to generate planets with random distances and random angles relative to the orbiting star, every single value is exactly the same through each iteration of the loop.

I initialise my seed function at the start of the level blueprint:

I don’t get what the problem is. Is this just a problem with UE4 where calling the same piece of code will force the seed back to a previous sequence?

That is great feature of seed.

You need to change seed to change generated numbers.

So if you want same system generated again just write down seed you like.

If you want different numbers every time initialize random stream with random seed, not with same seed.

But I thought the idea of a random seed was that it generates a sequence e.g 1,2,35,2090 based on the range you supply to it, so why does it repeat the same number for every iteration of a loop? I would have thought that the seed would continue its sequence and as a result I would get a different value for each iteration, but retain the same sequence every time I run the game.

The setting of the seed is what starts the sequence so if you set the seed in the loop it will always be the same.

You need to set the seed once. It looks like you set the seed for each number you want to generate, which is not correct – once the seed is set, the same numbers get generated from then on. Setting it every time means you generate the same numbers every time.

Separately: You are currently depending on the evaluation order between “pure” functions “random integer from stream.” The evalution order between the three return values MAY CHANGE in some future version of the engine, and if so, the returned star system will change, too. To fix this, you need to use a control flow node between each value; for example, use three local variables; Set them each in turn based on a random output, then return the values of those three local variables in your function return value.

I believe there might be an answer here: https://answers.unrealengine.com/questions/287638/blueprint-bug-using-a-random-stream-passed-to-a-fu.html

As John found, unless the random stream is passed by-reference the function will make a new copy of it, thus kind of defeating the purpose. If I’m guessing correctly you’re passing the variable named “seed” (which is acctually a random stream) to the planet generating function on each loop iteration?