View Single Post
  #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