Using a pseudo random number generator (PRNG) even simple with low weight seeds is certainly NOT a good solution. PRNG does not keep the Hamming seed weight constant, and the whole idea of PRNG is to remove seed information.
If you want cue ball with a fast value to be set to 1 of n, your question is a variant of these two questions. If k is much less than n, then the shuffle is O (n). I think the next solution is O (k).
It is based on this answer in python
from random import sample def konesoutofn(k, n): output=0 for d in sample(xrange(n), k):output+=(1<<d) return output x=konesoutofn(4,32) print(bin(x))
If you want to have approximately k bits of sets equal to one, then k / n is the probability that each bit will be equal to one, then you should look at Bernoulli and Geometric distributions.
Frédéric grosshans
source share