Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > General Gambling > Probability
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2007, 02:15 AM
Ganjasaurus Rex Ganjasaurus Rex is offline
Senior Member
 
Join Date: Sep 2007
Posts: 336
Default Looking for event-based random number generator

Sorry if this is the wrong forum. Wasn't sure where to put it.

Anyway, i'm looking for a random number generator that you can pre-program in the mean, SD, range, etc of n numbers. So in other words, let's say i want to generate 100 random numbers but want to make sure that the final mean and SD are predetermined. Is there such a program?

TIA
Reply With Quote
  #2  
Old 11-17-2007, 03:38 AM
RustyBrooks RustyBrooks is offline
Senior Member
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 1,380
Default Re: Looking for event-based random number generator

This sparked a small memory in me and I did a quick investigation and it seems to hold.

You can actually generate a series of random numbers that are normally distributed by adding together 2 numbers that are randomly generated by a linear distribution. I remembered this because when you roll 2 dice, the sum of the dice is a standard distribution.

You can adjust to scale to the desired mean/standard deviation.

So, if you know any kind of programming language, go through a loop 100 times and do this:

n1 = rand()*std*2.45
n2 = rand()*std*2.45
num = mean + n1 + n2 - std*2.45

Why 2.45? I don't know. But it works.

I wrote a quick program for it. I could probably throw it up on the web if you're interested.
Reply With Quote
  #3  
Old 11-17-2007, 03:54 AM
jukofyork jukofyork is offline
Senior Member
 
Join Date: Sep 2004
Location: Leeds, UK.
Posts: 2,551
Default Re: Looking for event-based random number generator

[ QUOTE ]
This sparked a small memory in me and I did a quick investigation and it seems to hold.

You can actually generate a series of random numbers that are normally distributed by adding together 2 numbers that are randomly generated by a linear distribution. I remembered this because when you roll 2 dice, the sum of the dice is a standard distribution.

You can adjust to scale to the desired mean/standard deviation.

So, if you know any kind of programming language, go through a loop 100 times and do this:

n1 = rand()*std*2.45
n2 = rand()*std*2.45
num = mean + n1 + n2 - std*2.45

Why 2.45? I don't know. But it works.

I wrote a quick program for it. I could probably throw it up on the web if you're interested.

[/ QUOTE ]
I thought when I first read his post that he wanted to generate Gaussian random numbers too, but I think he wants to generate sequences that have an exact mean and standard deviation (eg: generate 10 random numbers that have a mean of -2.8 and a std of 1.5).

Juk [img]/images/graemlins/smile.gif[/img]
Reply With Quote
  #4  
Old 11-17-2007, 04:05 AM
Ganjasaurus Rex Ganjasaurus Rex is offline
Senior Member
 
Join Date: Sep 2007
Posts: 336
Default Re: Looking for event-based random number generator

[ QUOTE ]
[ QUOTE ]
This sparked a small memory in me and I did a quick investigation and it seems to hold.

You can actually generate a series of random numbers that are normally distributed by adding together 2 numbers that are randomly generated by a linear distribution. I remembered this because when you roll 2 dice, the sum of the dice is a standard distribution.

You can adjust to scale to the desired mean/standard deviation.

So, if you know any kind of programming language, go through a loop 100 times and do this:

n1 = rand()*std*2.45
n2 = rand()*std*2.45
num = mean + n1 + n2 - std*2.45

Why 2.45? I don't know. But it works.

I wrote a quick program for it. I could probably throw it up on the web if you're interested.

[/ QUOTE ]
I thought when I first read his post that he wanted to generate Gaussian random numbers too, but I think he wants to generate sequences that have an exact mean and standard deviation (eg: generate 10 random numbers that have a mean of -2.8 and a std of 1.5).

Juk [img]/images/graemlins/smile.gif[/img]

[/ QUOTE ]
I want to make a gaussian curve of random numbers with a predetermined mean and SD. Does Rusty's program do that?
Reply With Quote
  #5  
Old 11-17-2007, 04:14 AM
RustyBrooks RustyBrooks is offline
Senior Member
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 1,380
Default Re: Looking for event-based random number generator

What I have will generate a sequence of numbers that have a given mean and standard distribution.
Reply With Quote
  #6  
Old 11-17-2007, 04:15 AM
RustyBrooks RustyBrooks is offline
Senior Member
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 1,380
Default Re: Looking for event-based random number generator

(normal distribution = gaussian distribution, so I'm not entirely sure what you mean)
Reply With Quote
  #7  
Old 11-17-2007, 04:25 AM
jukofyork jukofyork is offline
Senior Member
 
Join Date: Sep 2004
Location: Leeds, UK.
Posts: 2,551
Default Re: Looking for event-based random number generator

[ QUOTE ]
[ QUOTE ]
[ QUOTE ]
This sparked a small memory in me and I did a quick investigation and it seems to hold.

You can actually generate a series of random numbers that are normally distributed by adding together 2 numbers that are randomly generated by a linear distribution. I remembered this because when you roll 2 dice, the sum of the dice is a standard distribution.

You can adjust to scale to the desired mean/standard deviation.

So, if you know any kind of programming language, go through a loop 100 times and do this:

n1 = rand()*std*2.45
n2 = rand()*std*2.45
num = mean + n1 + n2 - std*2.45

Why 2.45? I don't know. But it works.

I wrote a quick program for it. I could probably throw it up on the web if you're interested.

[/ QUOTE ]
I thought when I first read his post that he wanted to generate Gaussian random numbers too, but I think he wants to generate sequences that have an exact mean and standard deviation (eg: generate 10 random numbers that have a mean of -2.8 and a std of 1.5).

Juk [img]/images/graemlins/smile.gif[/img]

[/ QUOTE ]
I want to make a gaussian curve of random numbers with a predetermined mean and SD. Does Rusty's program do that?

[/ QUOTE ]
It will sample them from the Gaussian distribution and if you take enough samples (millions) the sampled mean/std will eventually approach the true mean/std you asked for, but it can't be used to select a fixed length sequence that gives an exact mean and std each time.

The only method I can think of is to just generate lots and lots of fixed length sequences (using a suitable Gaussian RNG generator) and discard the ones which don't have the exact mean and std you are looking for. If the ordering matters then you can always permute the order of (and reuse) the sequences using a shuffling algorithm (eg: Knuth Shuffle) as the mean and std won't be affected by order.

This link and the GSL source-code might also be helpful.

Juk [img]/images/graemlins/smile.gif[/img]
Reply With Quote
  #8  
Old 11-17-2007, 04:33 AM
RustyBrooks RustyBrooks is offline
Senior Member
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 1,380
Default Re: Looking for event-based random number generator

Exact? No. But for 100-length sequences it's OK. No 100-sized sample from a general population with a given mean and standard deviation will have that exact mean and standard deviation anyway. OK, so here are some samples from mean=50, std=25. When n=1000 the means are all within about 1, and std is within .4

mean == 46.1312, std == 25.0674
mean == 47.3159, std == 24.4849
mean == 46.4967, std == 25.8444
mean == 44.4332, std == 26.5974
mean == 48.8557, std == 26.0069
mean == 47.8602, std == 25.5480
mean == 52.0704, std == 27.5603
mean == 49.9019, std == 27.4975
mean == 52.4116, std == 24.7947
mean == 48.9171, std == 24.2495
mean == 50.5276, std == 22.1211
mean == 52.2813, std == 27.1429
mean == 49.0307, std == 22.4335
mean == 51.0344, std == 27.2197
mean == 50.5114, std == 24.4022
mean == 51.7506, std == 26.0787
mean == 48.8765, std == 27.6355
mean == 46.4424, std == 23.5208
mean == 44.5342, std == 24.2434
mean == 42.9070, std == 24.9680
Reply With Quote
  #9  
Old 11-17-2007, 10:09 AM
BruceZ BruceZ is offline
Senior Member
 
Join Date: Sep 2002
Posts: 4,078
Default Re: Looking for event-based random number generator

[ QUOTE ]
You can actually generate a series of random numbers that are normally distributed by adding together 2 numbers that are randomly generated by a linear distribution.

[/ QUOTE ]

Numbers generated this way are not normally distributed. You need to add more than 2 numbers in order to adequately approximate a normal distribution by the central limit theorem. Adding 2 uniformly distributed numbers gives a triangular shaped density function, not a normal bell curve.

[ QUOTE ]
I remembered this because when you roll 2 dice, the sum of the dice is a standard distribution.

[/ QUOTE ]

The sum of 2 dice follows the discreet version of the triangular shaped density function.


[ QUOTE ]
n1 = rand()*std*2.45
n2 = rand()*std*2.45
num = mean + n1 + n2 - std*2.45

[/ QUOTE ]

If rand() is the standard uniform distribution on [0,1], this will generate numbers with the given mean and standard deviation, but the density function will be triangular in shape.


[ QUOTE ]
Why 2.45? I don't know. But it works.

[/ QUOTE ]

The value 2.45 is an approximation for sqrt(6). Your formula can be written as

num = mean + sqrt(6)*std*[rand() + rand() - 1]

The variance of the uniform distribution rand() is 1/12, so the variance of rand() + rand() is 1/6. Subtracting 1 does not change the variance, so the standard deviation of the term in brackets is 1/sqrt(6), so multiplying by sqrt(6)*std gives the desired standard deviation.

This post gives a method for generating normally distributed random numbers from uniformly distributed random numbers if you have access to the inverse normal function as in Excel. Another method is to use the Box-Muller transformation. I have generated normally distributed random numbers by simply adding together a sufficiently large number of uniformly distributed random numbers (as from the rand() function).

If the OP requires that every set of n numbers he generates has the same mean and standard deviation, then he can use one of the other methods in this thread to scale the final numbers to achieve this. Normally distributed numbers would show some variation in the actual mean and standard deviation for each set of n numbers. These variations become small as n becomes large. The methods in this post will generate numbers which are distributed as a normal distribution with the desired mean and standard deviation, and the actual computed mean and standard deviation for each set of n numbers will vary as they should.
Reply With Quote
  #10  
Old 11-17-2007, 01:05 PM
RustyBrooks RustyBrooks is offline
Senior Member
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 1,380
Default Re: Looking for event-based random number generator

Ah, OK, my bad. I don't know where I remembered it from, but my memory is kind of bad. The transformation stuff is interesting also.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.