Creating a random number generator with a defined start/end range and standard deviation

Hi,

I have a sheet that creates 5 cols by 50 rows (250 numbers) using randbetween of two defined values, usually between 5 and 30. These individual rows are then averaged (5 numbers averaged to generate 1) so in total 50 numbers.

These values are then used to create a normal distribution histogram.

However, I would like to define a number in row 1 of each of the 5 columns which will act as the standard deviation expected. So once the figures are created and the average of the 5 cols is created, the overall standard deviation of the 50 figures is equal to that defined.

Few questions, please...
(1) Is B1 the target? (The sheet says B10.)
(2) Did you mean the target to be 10? That's an enormous distance from anything that would be expected.
(3) "Close as possible" needs to be defined. +/- 10%, 1%, .1%?

Please see the attached. Press the blue button to run a macro that cycles through up to 100 random iterations looking for the first solution within 1% of the target. The code is...

Option ExplicitSub Randomish()Dim xMin As DoubleDim xActual As DoubleDim xTarget As DoubleDim i As LongSheets("Sheet2").ActivatexTarget = Range("B1")xMin = 100000000Application.ScreenUpdating = False For i = 1 To 100 Range("B6:F105").Formula = "=(RANDBETWEEN($B$3,$B$4)+(RANDBETWEEN(0,9)/100))" Range("B6:F105").Copy Range("B6:F105").PasteSpecial xlPasteValues xActual = Range("H1") If Abs(xTarget - xActual) / xTarget < 0.01 Then MsgBox ("Run complete - difference is " & Format(Abs(xTarget - xActual) / xTarget, "0.00%")) Exit Sub End If If Abs(xTarget - xActual) < xMin Then xMin = Abs(xTarget - xActual) NextMsgBox ("Sorry - couldn't get within reach. Closest was " & Format(xMin / xTarget, "0.00%") & ". Please try again.")Application.ScreenUpdating = TrueEnd Sub

Thanx for that, problem is obviously if Randbetween values are say 8-15 as they are then unlikely to get a 10 deviation which is expected, however even when I change the range from 8-30 and set the deviation to 10, it does not seem to get much higher than 3?

1) Yes sorry typo B1 is target.
2) Would not expect it to be bang on 10, but near as possible, expecting exactly 10 would cause massive delay in calculating.
3) I would say +/- 20% would be a exceptable range.
4) Excel 2010.

expecting exactly 10 would cause massive delay in calculating.
Spot on - an SD of 10 isn't quite age of the universe stuff, but I think it'd comfortably see the pair of us dead and buried. (For normally distributed data, the odds of getting an SD of even 7 is 1/390,682,215,445.)

What is the table for?

Regards,
Brian.

0

MirageSFAuthor Commented:

Brian, like the dead and buried before calculation lol.

The table will be used for simulation data, generally looking for a deviation for each set of around 1-3 points, but occassionaly will need this to be around 10 if defined, although rare and more likely to stay 5 or below.

Is it not possible to have the random values as they are created now, but occassionaly add a bump value of say 10 to force the overall average up and therefore bring the deviation closer to target?

The attached will now generate a match between B1 and H1 of <= +/-1%. However, I think it would be fair to describe it as a statistical abomination. :)

Please note that I've moved the Max and Min figures up a row to make room for the "Adjustment Factors" above each column.

Finally, you'd be doing yourself a favour if you deleted this question and opened a new one - this time including the Mathematics Topic (as well as Excel)!

Yes, that was my first thought, but this one is a lot simpler (assuming that MirageSF is content with the above).

Regards,
Brian.

0

MirageSFAuthor Commented:

Hi Barman,

Yes you are correct, it was your mathematical genius which created that for me, for which I have been using for a while now. However, that version allowed me to define the range i.e. 8-15 which was great, but no control really over individual Average & Standard Deviation values which I required later on.

The updated version I am using NORM.DIST to generate my random numbers which gives me good control over average and standard deviation, but zero control over the range!. Unless I use MEDIAN in front of the NORM.DIST command as matthew Patrick pointed out, but this then does not create normal distribution.

So each column of 50 numbers needs range from range to, deviation and average expexted values, and then needs to generate 50 numbers with these factors which would be normally distributed.

0

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Sample.xlsx