Re: Looking for event-based random number generator
If i understand correctly, you want a gaussian looking sample with an exact mean/sd?
All you have to do is generate some kind of gaussian sample, and then transform it by:
sample_mean = mean(x in sample)
sample_sd = sd(x in sample)
for(x in sample)
x = (x-sample_mean)*desired_sd/sample_sd + desired_mean;
In R this would look something like that, for producing a sample of 10 with exact mean=10, sd=3:
<font class="small">Code:</font><hr /><pre>> x=rnorm(10)
> x
[1] 2.09314362 0.99306790 -0.87603143 1.26745925 -0.03479952 -1.35067764
[7] 0.80660410 0.38489743 -0.59618511 1.98929586
> x = (x-mean(x))/sd(x)*3+10
> x
[1] 14.139231 11.337901 6.578261 12.036635 8.720448 5.369580 10.863073
[8] 9.789202 7.290887 13.874783
> mean(x)
[1] 10
> sd(x)
[1] 3
</pre><hr />
Edit: Oh yay, Gibert just posted exactly the same. lol
|