I want to create a shuffled set of integers such that:
This option gives a great solution if you want, say, all of the numbers between 0 and a specified number: Generating Shuffled Range Using a PRNG Rather Than Shuffling
Any ideas?
You can use the exact same algorithm as the linked question. Just generate numbers between 0 and upperBound - lowerBound + 1
and add lowerBound
to the result.
e.g. (using code from linked question):
var upper = 5;
var lower = 3;
foreach (int n in GenerateSequence(upper-lower+1))
{
Console.WriteLine(n+lower);
}
If you want the sequence to repeat (shuffled differently each time), you can add a while (true)
around the iterator method body.