Download

Unique consecutive random integer

Need to generate a unique consecutive random integer.
In pseudo code it would be something like this
1 Create local class variable of type int, lets call it _PrevIndex
In Loop
2 Generate random integer
3 Is this random integer = _PrevIndex?
4 If yes, go to 2
5 If no, continue and set _PrevIndex to this random integer

Sometimes the specific node connections throws my head for a spin. If I have the attached (which runs in a For Loop) , can anyone hep with the specific nodes and connections I would need for the above logic?

Like this:

The problem with storing previous ints, is the code gets slower and slower as they run out.

1 Like

Thanks your solution looks quite elegant and would perform well.
But I have just a small pool of ints 10 or less that I need to repeatedly call 1000s of times.

Ok, just the same if you call 10 lots of times. You’ll spend most of your CPU time trying to find the missing number.