I can't understand how the RANDOM block works

Since there is no built-in “random” node, I assume you are referring to nkrkv/random, which returns a number between 0 & 1. You can either split this into 4 equal parts or multiply by 4 & round to get a number between 1 & 4.

You will need to use logic to determine which flip-flop to toggle based on the random number.
image
One side-affect of this code is that it will not toggle same flip-flop consecutively. If random returns same range twice in a row, flip-flop will only toggle once. This is because TGL only triggers when boolean changes from false to true.

You could add additional nodes to activate flip-flop from same pulse that updates random so the same flip-flop could be changed more than once before any others are changed.


The defer node is only to make sure less/not/and compares have completed before pulse is sent to gate nodes. The “not” of “less” is the same as testing for “greater-or-equal” of the same value, but requires less CPU since we have already done the “less” compare.

It appears random function is not supported in simulator, so I haven’t tested this code.