Convert 32 bit uniform distribution to uniform distribution on any int

182 Views Asked by At

Given a discrete uniform distribution D~U([0:2^N-1] from which a sample yields a number in the inclusive integer range [0, 2^N-1] for an integer N, I need a function convert such that for a sample d~D, convert(d, m) will have an integer uniform inclusive distribution Dc~U([0:m]).


Thoughts:

  • If the distribution is continuous, this is easy. Just cutoff the infinite representation of the number, and the uniformity is preserved.
  • I can't think of a way to do this for all numbers and keep uniformity.
  • I could re-roll for tie conditions, but am not able to formulate an algorithm.

What I eventually want, is a murmur hash on a custom range (m), rather than exact 32 bit numbers.

0

There are 0 best solutions below