(Redirected to haskell-cafe.)

On Mon, May 06, 2002 at 04:49:55PM -0700, [EMAIL PROTECTED] wrote:
> Problem: given an integer n within [0..maxn], design a scaling
> function sc(n) that returns an integer within [s..t], t>=s.
> The function sc(n) must be 'monotonic': 
>       0<=a < b ==> sc(a) <= sc(b)
> and it must map the ends of the interval:
>       sc(0) -> s and sc(maxn) -> t.

Just an aside (which Oleg surely knows): for actual random number
generation, you often don't care about the monotonicity, and only care
about uniform generation.  In this case, there is a very simple
algorithm: work modulo (s-t+1).

  scm(n) = (n `rem` (s-t+1)) + s

Warning: some, broken, random number generators do not behave well
when used like this.  Also, although this is as uniform as possible,
there is a systematic skew towards the lower end of the range [s..t].

--Dylan Thurston

Attachment: msg01661/pgp00000.pgp
Description: PGP signature

Reply via email to