Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Random numbers
Replies: 64   Last Post: Dec 24, 2007 1:04 PM

 Messages: [ Previous | Next ]
 William Elliot Posts: 4,698 Registered: 3/18/05
Re: Random numbers
Posted: Dec 21, 2007 7:44 AM

On Fri, 21 Dec 2007, John 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.
>

Between 1 and 5 for real numbers means in (1,5).
Given a random r in (1,5), 6(r - 1)/4 + 1 is random in (1,7).

A random integer between 1 and 5 is 2, 3 or 4.
A random integer between 1 and 7 is 2, 3, 4, 5 or 6.

Let r be a random number in { 2,3,4 }.
Let s = 0, if r = 2
1, if r = 3
goto let s if r = 4

s is a random binary number.

Let t = 1 if r = 2, s = 0
2 if r = 2, s = 1
3 if r = 3, s = 0
4 if r = 4, s = 1
5 if r = 5, s = 0
6 if r = 6, s = 1

t is a random number in { 1,2,3,4,5.6 }.

Let d = t if t /= 1
goto let d if t = 1

d is a random number in { 2,3,4,5,6 }.

Date Subject Author
12/21/07 Champ
12/21/07 quasi
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 Marshall
12/21/07 Phil Carmody
12/21/07 quasi
12/21/07 Phil Carmody
12/21/07 Marshall
12/21/07 briggs@encompasserve.org
12/21/07 William Elliot
12/21/07 quasi
12/22/07 William Elliot
12/21/07 Pubkeybreaker
12/21/07 b92057@yahoo.com
12/22/07 quasi
12/21/07 simple.popeye@gmail.com
12/21/07 simple.popeye@gmail.com
12/22/07 quasi
12/22/07 Gib Bogle
12/22/07 quasi
12/21/07 Marshall
12/22/07 simple.popeye@gmail.com
12/22/07 quasi
12/22/07 simple.popeye@gmail.com
12/22/07 quasi
12/22/07 quasi
12/22/07 quasi
12/22/07 simple.popeye@gmail.com
12/22/07 quasi
12/23/07 simple.popeye@gmail.com
12/23/07 simple.popeye@gmail.com
12/23/07 simple.popeye@gmail.com
12/23/07 simple.popeye@gmail.com
12/23/07 simple.popeye@gmail.com
12/22/07 simple.popeye@gmail.com
12/22/07 Herman Rubin
12/22/07 b92057@yahoo.com
12/22/07 quasi
12/23/07 b92057@yahoo.com
12/23/07 quasi
12/23/07 b92057@yahoo.com
12/24/07 quasi
12/24/07 quasi