Search code examples
mathrandomgeneratornumber-theory

Pseudorandom Number Generator with slight bias


I've thought about this for a while to no avail...

How would one go about creating a pseudorandom number generator with a slight (we're talking only apparent after millions, maybe billions, of iterations/tests) bias towards a single number. So, for example, if our generator is producing numbers from 0,1,2,...,98,99 and we want the slight bias for 47.

I feel as though there should be a clever Number Theory kind of solution to this but I couldn't find anything. Curious to see what y'all think!


Solution

  • You can use any good random generator with uniform distribution.

    If your subrange has length N, generate values in range 0..K*N+1 (not including right border). If result R is less than K*N, output R mod N, otherwise output preferred value.

    In this case we have probability for all elements p=K/(K*N+1) and for preferred element probability q = p + delta = K/(K*N+1) + 1/(K*N+1) = (K+1)/(K*N+1).

    If you have N and some bias criteria, calculate K to provide close bias value.

    If you need more precision, use random range 0..K*N+F with corresponding formula corrections (this approach gives any needed rational value of bias).