#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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] |
#4
|
|||
|
|||
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? |
#5
|
|||
|
|||
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.
|
#6
|
|||
|
|||
Re: Looking for event-based random number generator
(normal distribution = gaussian distribution, so I'm not entirely sure what you mean)
|
#7
|
|||
|
|||
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] |
#8
|
|||
|
|||
Re: Looking for event-based random number generator
[ QUOTE ]
(normal distribution = gaussian distribution, so I'm not entirely sure what you mean) [/ QUOTE ] Unless I've misread his OP, I think he wants to generate fixed length sequences which have a certain mean/std (as opposed to sampling from the Gaussian distribution). Juk [img]/images/graemlins/smile.gif[/img] |
#9
|
|||
|
|||
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 |
#10
|
|||
|
|||
Re: Looking for event-based random number generator
There's no way to get an exact mean/std in this way without doing what you suggested and rigorously weeding. I doubt that's what he wants though.
|
|
|