1

Given a random number generator r() which produces a (pseudo-)random double in the interval [0,1] with uniform density, ie p(x) = 1 for 0 <= x <= 1 and p(x) = 0 elsewhere, create a random number generator r(a,b) which generates a double in the interval [a,b] with density p(x) = 1/(b-a) for a <= x <= b.

bountiful
  • 814
  • 1
  • 8
  • 22

1 Answers1

-1

I believe (and have tested) that this produces a uniform distribution.

r(a,b) = ((r * b) mod (b-a)) + a

but is there another more obvious way?

Yes:

r(a, b) = r*(b-a) + a
bountiful
  • 814
  • 1
  • 8
  • 22