How to find randomly selected integer?

All dependant pure nodes are re-evaluated for each exec node.

So simply put :


This works because here the RANDOM node is dependent twice on the same exec node (print string), so RANDOM is executed only once and its results are cached during this specific evaluation.

However :


This doesn’t work because RANDOM is executed once for the first Print String exec, and another time for the second Print String exec (giving a different value).

Solution : as a rule of thumb, avoid wiring multiple outputs (or one output multiple times) of pure nodes if they are not consistent or have side effects. Immediately store the appropriate result in a variable and use that variable. By appropriate I mean, if you don’t need the index it’s perfectly fine to use item directly. If you do need the index, store the index and get the item back from index.

5 Likes