I read a couple of posts here about generating random sequence without repeats (for example Create Random Number Sequence with No Repeats) and decided to implement it for my own need
Actually it was an algorithm applying some non-destructive (reversible) operations with the bits of the current counter in order to get a pseudo-random number that should appear only once. Since the operations are reversible, different source numbers will give different result numbers.
There are at least several operation possible like exchange two bits, invert a bit, cyclic shift. If we use only ones mentioned, the quality of the sequence won't be great since the nearby counter will produce results with similar number of zeros and ones. The real game changer was xor one bit by another bit. Now the sequences looks much better, but the questions are:
UPDATE: As I posted in the comment here, there's already a generator like this: AES Encryption, but unfortunately it can only be used for 128-bit ranges.
Thanks
Max
Problem:
Generate a list of unique random integers between 1 and N.
Solution:
In Matlab:
z = rand( [N 1] );
[dummy iz] = sort(z);
% iz is your list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With