lol, did u even bother to test it??
Your reasoning is fundamentally flawed, because if rand() gave such predictable results, the distribution should be the least of your concerns. |
I believe I m being misunderstood :/ I don't intend to make rand() give predictable results.
What I want is to make it so that the fact that the distribution is uniform becomes apparent within only few calls. What I wrote does exactly that. Anyway I just came up with another way to do it. Let's say that we want a number between 1 and n. We could make rand() pick a number from a predefined sequence where we'd put m permutations of the multiset {1,...,1,2,...,2,3,...3,n,...,n}, where 1 is contained k times, 2 is contained k times etc. Let's say, for example, that you want to draw a number from 1 to 5 and take m=9 and k=3. A sequence where rand() could draw from could be:
{1,1,1,2,2,2,3,3,3,4,4,4,5,5,5, 1,2,3,4,5,1,1,2,2,3,3,4,4,5,5, 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,
1,3,5,2,4,1,2,3,4,5,1,3,5,2,4, 1,1,2,3,3,4,5,5,1,2,2,3,4,4,5, 5,4,1,2,3,5,4,3,2,1,2,4,1,3,5,
1,2,2,3,4,4,5,1,1,2,3,3,4,5,5, 1,5,2,4,3,5,1,2,4,3,1,2,3,5,4, 5,5,1,2,3,4,4,2,3,4,3,5,2,1,1}
What do you think about that?