Random Integer node weirdness explanation anyone?

The Random integer node does some weird things.

For example what it outputs to a Print string can be different to what it inputs into a input pin elsewhere in your code.

Can someone explain why it does this and why it feels so unreliable? What’s going on with it? Why is it like this?

(FYI: The best solution is to immediately output the random node to a Set variable, then use a Get variable where you need it in that blueprint.) But why must it be this way?

Pure nodes are evaluated every time a node with an execution pin accesses them. It applies to everything in the engine, not only randoms. This will execute the function twice:

Note that non-pure nodes do cache return values, as in:

1 Like

Pure nodes are evaluated every time a node with an execution pin accesses them. It applies to everything in the engine, not only randoms.

Feels great to finally know why this happens!! Thanks!

1 Like

One last related note:

Even though we execute once and are interested in Option 1 only, both functions will run. If you do not police yourself and add non-local setters inside pure functions (BPs let you do it), the values will change since the functions run.

Rather than just Branching to False:

This will run all 3 expensive functions and then Branch to False :innocent: