• News

• Industries

• Learning & Support

• Community

• Marketplace

# Understanding Random Seed

I’m currently studying blueprints, so far I’m looking into the BlueprintOffice example from the launcher vault.

Something in the BP_Random_Foliage graph is not entirely clear with me:

&stc=1

The part of the graph that creates the Spawn Point vector uses a couple of functions to generate a random float, which in turn is collected to form a vector. But all of those random generators seem to only use a single Random Seed value.

How is it possible that the Spawn Points seems to get randomized even if the seed is not incremented on each iteration of the loop?

Or is that a feature of the **Random X from Stream **functions, where it knows if you are in a loop, and will change seeds internally?

Random float from stream will give you the same sequence of different numbers every time you re-start the game. Random seed is what changes this sequence. For example, with random seed 100 you will always have 1,5,10,12,8,3. And for seed 200 you will have 50,3,8,13,4,91. (It’s not a true example of course, just to show how it work).

Hi Scha, thank you for the response

Yes, that is also my understanding of random generators and seeding… but as with the case above, I’m kinda lost on the part where it is able to generate random Spawn Points.
The Random Seed is unchanging, yet on every iteration of the ForLoop, the result is randomized.

Something like this is what I’m seeing on the graph from the screengrab above:

``````

spawn_points = [0,0,0]
seed = 12345
for i in range(10):
spawn_points = random_vector(seed)

``````

The seed is unchanging… thus the resulting values of the spawn_points should be the same.

This is more of what I had in mind that makes sense:

``````

spawn_points = [0,0,0]
seed = 12345
for i in range(10):
seed += i
spawn_points = random_vector(seed)

``````

Here, the seed is incremented, so the spawn_points should have changing random vector values.

I suppose as a new user of UE4 and Blueprints, I will have to play around and test these functions a bit more :D, my perception of how familiar things work (as with other DCC apps) is fogging my view on working in Blueprints.

From what I understand, a “Random” function only needs to get seeded once and then can continually output random numbers. So the seed doesn’t need to change for every iteration of the loop to get random numbers.

@Galagast You will have different spawn points without changing the seed. BUT, next time you play you will have the same sequence of spawn points.

See the attached picture. Try to put that in a level bp, hit play/stop few times and see what it prints.

Awesome scha. That graph finally makes a lot more sense

My brain is now translating the graph to something like so:

``````

random_seed_stream = [0,6,8,4,3,1,9,8,5...] # consistent set of random values
for i in range(10):
seed = random_seed_stream*
val = random_integer(seed)
print val

``````

I missed the part where the Random Seed variable was of “Random Stream” type… All the while, I thought it was a regular integer. I need to get more familiar with the variable types and color schemes of UE4

Thank you guys for the replies, it helped a lot.
Cheers!

1 Like

Thanks for coming back to follow up on this. I understand now too!

Basically a random function is just a math function.
A random function can’t work without seed. But it can, because it automatically use the system time as the seed.

Random with seed is either for the platform doesn’t have system time (mostly on old consoles, like ps1, ps2, etc.) or you just want to control the randomization.

So, if you want a true random, don’t use random with seed.