IIUC, you want “random sampling without replacement.” In this context (workalike of RAND) it seems nontrivial to me.

(thinking about opcode inementation here, not scripting)

The standard method with N values, is to make an array of size N filled with the values, and shuffle it every N samples. (If adjacent endpoints of new and previous shuffled states are the same, and you don’t want them to be, rotate the new shuffled state I guess.)

The problem with that algo here, if N is the full range of values in TT, that N is very big compared to the cpu speed and RAM size. Shuffling is too costly.

The problem with just re-rolling until you get a new value, is that there is no upper bound on how many re-rolls you need. And sometimes it will take a lot, because this function will be called uncountable times and we run into the law of very large numbers. We don’t like non-deterministic compute times in soft-realtime systems.

If you are OK with occasional repetitions then it seems fine to re-roll no more than K times. Then your likelihood of repetition is 1/(16000 * K) or something.

If you’re never ok with it I would consider a different approach, like building a smaller sequence of values for randomization and using a shuffle.

Now that I said I’ll that: since in this specific case you’re talking about a very small number of values, the shuffle method is clearly the way to do it. How to structure that as an opcode I’m not sure. Maybe it just has a fixed, small number of values, like N=16 or something.

And hm, since statistical randomness probably isn’t a requirement, maybe some kind of simple hashing function could do the trick …

[ed]… as @scanner_darkly shows below!