On Fri, 21 Dec 2007 03:16:21 -0800 (PST), John <email@example.com> wrote:
>Given a function that returns a random number between 1-5, write one >that returns a random number between 1-7 for the case when it should >be integer and for the case it can be real.
Here's a simple way ...
Assume you have a function which returns a random integer (uniformly distributed) from 1 to 5. Generate 2 such random integers, x1, x2, and let x = x1 + 5*(x2 - 1). Then x is a random integer from 1 to 25. If x is greater than 21, reject x and try again, otherwise, return (x mod 7) + 1
Assume you have a function which returns a random real (uniformly distributed) from 1 to 5. Then generate one such random real, x say, and let y =(3/2)*(x-1) + 1. Then y is a random real from 1 to 7.