Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-25
12
Medium Priority
?
226 Views
Last Modified: 2013-09-25
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.

How could I do this?

My initial sheet attached
0
Comment
Question by:MirageSF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
12 Comments
 

Author Comment

by:MirageSF
ID: 38821070
Sorry, fixed sample as attached, please use this one thx
Sample.xlsx
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38821397
MirageSFP,

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%?

Edit: What version of Excel?

Brian.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38821420
MirageSFP,

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 Explicit

Sub Randomish()
Dim xMin    As Double
Dim xActual As Double
Dim xTarget As Double
Dim i       As Long

Sheets("Sheet2").Activate

xTarget = Range("B1")

xMin = 100000000

Application.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)
        
    Next

MsgBox ("Sorry - couldn't get within reach. Closest was " & Format(xMin / xTarget, "0.00%") & ". Please try again.")

Application.ScreenUpdating = True

End Sub

Open in new window

Regards,
Brian.Sample--4--V2.xlsm
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MirageSF
ID: 38821627
Hi Brian,

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.

Thank you
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38821665
MirageSF,

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
 

Author Comment

by:MirageSF
ID: 38821706
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?

Cheers
0
 
LVL 26

Accepted Solution

by:
redmondb earned 2000 total points
ID: 38821742
MirageSF,

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)!

Regards,
Brian.
Sample--4--V3.xlsm
0
 
LVL 24

Expert Comment

by:Steve
ID: 38826337
Isn't this a very similar question to this one:

http://rdsrc.us/9qtQNl
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38826383
The_Barman,

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

Regards,
Brian.
0
 

Author Comment

by:MirageSF
ID: 38826400
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question