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

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 quasi Posts: 12,067 Registered: 7/15/05
Re: Random numbers
Posted: Dec 21, 2007 7:15 AM
 Plain Text Reply

On Fri, 21 Dec 2007 03:16:21 -0800 (PST), John <iamachamp@gmail.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 ...

Random integers:

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

Random reals:

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.

quasi

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 adder
12/22/07 simple.popeye@gmail.com
12/22/07 Herman Rubin
12/22/07 adder
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
12/24/07 adder
12/24/07 quasi
12/24/07 adder
12/24/07 b92057@yahoo.com

© The Math Forum at NCTM 1994-2018. All Rights Reserved.