hi all,

need some guidance :)

how can i produce a uniform distributed mapping function, from integers(let's assume less than 2^31) to integers between 0..n?

help would be appreciated!

Printable View

- June 25th 2012, 04:21 AMdoomsq:uniform distributed mapping func
hi all,

need some guidance :)

how can i produce a uniform distributed mapping function, from integers(let's assume less than 2^31) to integers between 0..n?

help would be appreciated! - June 25th 2012, 05:54 AMmfbRe: q:uniform distributed mapping func
There is no general way to uniformly map all integers from 0 to m to the set 0...n unless (n+1) is a divisor of (m+1). In this case, just take the number mod (n+1).

However, you can do the following: Determine the largest k such that k*(n+1)<=m. If the random number is <k*(n+1), use this number mod (n+1), otherwise get a new random number.

This is not the most efficient way to use your source of randomness, but for small n the difference is negligible. - June 27th 2012, 02:17 PMawkwardRe: q:uniform distributed mapping func
- June 28th 2012, 03:09 AMdoomsRe: q:uniform distributed mapping func
yes! that was a dumb question by me. nothing's really random.

% n+1 will do.

sweet, thanks.