Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 22, 2007 6:05 AM

On Fri, 21 Dec 2007, quasi wrote:
> <marsh@hevanet.remove.com> wrote:
> >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

>
> Very strange. How can r be 4,5,6? The variable r was generated as a
> random integer from the set {2,3,4} with rejection and retry if r = 4,
> so its value must be either 2 or 3.

Oh shucks, the last problem of the night after
I should have gone to sleep.

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

> >t is a random number in { 1,2,3,4,5.6 }.
>
> ??? How did you generate t? There's no mention of t before the above
> line.

It's the random variable
t = 2(r - 2) + s + 1

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

>
> The above 2 lines yield an infinite loop if t = 1.
>

> >d is a random number in { 2,3,4,5,6 }.
>
> Even if your algorithm can be corrected so as to make sense, you're
> making it more complicated than it needs to be.
>

Let t(rnd) be a random variable in { 1,2,3,4,5,6 }
giving a random value each time it's invoked.

:again; tt = t(rnd)
if tt = 1, then goto again
print tt
end

Something similar was done for your algorithm.

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