Randomly generate x whole numbers with sum of y with Excel - excel

I was referring to this post on generating random x numbers using =RAND(), however it cater for every number including those with decimal. I want to generate only positive whole number (e.g. 1, 3, 50) and not those with decimal.
To be clear, for example, I want to generate:
50 random positive whole numbers that has the sum of 1000
PS: If you find this question for Excel solution redundant, let me know and I'll close this.

I offer a solution which has better statistical properties than I had originally supposed:
Estimate the upper limit of each number as being twice the mean. In your case the mean is 20 (1000 / 50), so the upper limit is 39, as the lower limit is 1.
Generate 50 floating point numbers using
=RAND() * 38 + 1
Sum the total that you get, call that s
Rescale each number by multiplying by 1000 / s, and round the result in the normal way. (Use ROUND.)
Sum that. Call it t.
If t is less than 1000, add 1000 - t to the smallest number. If it's greater than 1000, subtract t - 1000 from the largest number.
This should be approximately uniformly distributed and have a good mean. You can run the results through some statistical tests for randomness to gauge whether or not it will fit your requirements. My instinct suggests to me that it will not be much worse than Rand() itself.

Related

Calculating number of hours spent per product, with diminishing effort

I want to calculate the number of work hours it takes to produce X. The first X takes 20 hours, but for each X it takes 20% less time. However, it will always take a minimum of 2 hours.
Any help is appreciated.
In Excel, this is really easy: 20% less means you are calculating 80% of the value, which in fact means that you are multiplying the value with 0.8.
As the value can't go below 2, you can simply take the maximum between the calculated value and 2, using the formula:
=MAX(2,0.8*A1)
The result looks as follows:
Have fun!
In order to calculate the sum, you can use the simple formula =SUM(A$1:A2) up to the end, as you can see in following screenshot:
An individual term of a geometric series is given by
The sum of a geometric series is given by
where in your case a=20 and r=0.8
You can show by taking logs or by trial and error that in your particular case you have
0.8^10 = 0.107374
so when n=11 you can see that the time has diminished to just over 2 hours. After that each rep takes 2 hours. So you have
=a*(1-r_^MIN(C2,11))/(1-r_)+MAX(0,C2-11)*2
for the total.
If you just want the time per item, it's
=IF(C2<=11,a*r_^(C2-1),2)
where a and r_ are named ranges for a and r, and the values of N are in column C.

Excluding 'N/A' answers in Excel table

Say I have a table of survey results. The scores for each answer are from 1-4 inclusive (1 worst, 4 best). An 'N/A' answer is represented as 5 - misleading when analysing!
I want to use a function in the final column that calculates the respondent's overall score for the survey. Rather than replacing 5 with 0 for a 'N/A' answer, I'd like to simply exclude that number altogether, and also exclude it from the overall maximum.
For example, say my maximum overall survey score was 80. If someone puts 'N/A' for one question, then I'd like their score to be n / 76, rather than n / 80.
Any suggestions? Feel free to ask for clarification if needed.
EDIT: See below for example image. I'm trying to get Overall Score / Max Score.
So after playing around with the available functions I stumbled across 2: COUNTIF and SUMIF.
As above, I'm trying to calculate Overall Score / Max Score.
So the formula I use is:
=SUMIF(range, "<5") / (COUNTIF(range, "<5")*4)
Stepping through the function:
=SUMIF(range, "<5") calculates the overall score (any number less than 5, ignores text)
(COUNTIF(range, "<5")*4) calculates the number of cells with numbers less than 5, ignores text. I then multiply this by the maximum score for a given question (which was 4). This gives me the maximum score possible given the number of 'N/A' responses.
Finally I divide the former by the latter and get the score I'm looking for. Hope this helps!

How to generate random numbers within a normal distribution using Excel

I want to use the RAND() function in Excel to generate a random number between 0 and 1.
However, I would like 80% of the values to fall between 0 and 0.2, 90% of the values to fall between 0 and 0.3, 95% of the values to fall between 0 and 0.5, etc.
This reminds me that I took an applied statistics course once upon a time, but not of what was actually in the course...
How is the best way to go about achieving this result using an Excel formula. Alternatively, what is this kind of statistical calculation called / any other pointers that I can Google around for.
=================
Use case:
I have a single column of meter readings, which I would like to duplicate 7 times (each column for a new month). each column has 55 000 rows. While the meter readings need to vary for each month, when taken as a time series, each meter number should have 7 realistic readings.
The aim is to produce realistic data to turn into heat maps (i.e. flag outlying meter readings)
I don't think that there is a formula which would fit exactly to your requirements. I would use a very straightforward solution:
Generate 80% of data using =RANDBETWEEN(0,20)/100
Generate 10% of data using =RANDBETWEEN(20,30)/100
Generate 5% of data using =RANDBETWEEN(30,50)/100
and so on
You can easily change the precision of generated data by modifying the parameters, for example: =RANDBETWEEN(0,2000)/10000 will generate data with up to 4 digits after decimal point.
UPDATE
Use a normal distribution for the use case, for example:
=NORMINV(RAND(), 20, 5)
where 20 is a mean value and 5 is a standard deviation.

Give 9 gifts to 5 users

Ive created a game and in that game played 5 users which collected few points, Ive gived gifts manually but for next games how can i split or make in excel to calculate number of gifts,
this is ok using number format with 0 decimal places, 6+1+1+1 = 9
but in cases like this:
1+6+1+1+1 = 10, how can I make that only 9 gifts results?
You should be comparing their percent (B2/SUM(B2:B6)) against each prize as it relates to the total prize (e.g. 1/9). Since you are comparing decimal numbers with another decimal number and expecting an integer (no. of prizes), you will be rounding either up or down depending on whether you are favoring a wider distribution of the prizes or favoring the top score.
Either way you are going to have to decide whether the lowest score should always receive a prize or if the highest score should benefit from the points awarded.
The three possible formulas to start with would be,
=MROUND(C2, 1/9)*9 ◄ closest to even distribution
=FLOOR(C2, 1/9)*9 ◄ favours wider prize distribution
=CEILING(C2, 1/9)*9 ◄ rewards highest awarded points
Fill down as necessary.
Now you have to either take the highest or lowest score and adjust that to compensate for rounding the division of decimal numbers to an integer. MROUND doesn't play well with SUMPRODUCT but these two may give you a solution that you can live with.
=FLOOR($C2, 1/9)*9-((SUMPRODUCT(FLOOR($C$2:$C$6, 1/9)*9)-9)*($C2=MAX($C$2:$C$6)))
=CEILING($C2, 1/9)*9-((SUMPRODUCT(CEILING($C$2:$C$6, 1/9)*9)-9)*($C2=MAX($C$2:$C$6)))
Fill down as necessary.
If the MROUND solution is best suited to your prize distribution model, use a helper column that can determine the MROUND returns and then adjust the high score according to the sum of the helper column without circular references.

How to convert floats into compound fractions with specific denominators?

I need to convert floats into numbers that resemble measurements from a ruler. For example: 3.75 needs to be converted into 3 and 3/4. However, this is harder than it would seem at first, because I need to keep the denominator in a form that is easily translated into a ruler measurement by a human. Essentially, the denominator should only be powers of 2, up to 16. I don't want a fraction like 3/5 because 5'ths aren't marked on a ruler. I have figured out how to limit the denominator from going above 16, but I can't figure out how to keep the denominator a power of 2.
Answers in python or c++ is preferred.
extract integer part, so you have fraction part less than 1.
find nearest 16th of fraction: multiply by 16 and round to nearest integer. Have some policy to break ties (e.g. round to even). I believe this step can't introduce floating point arithmetic error because you are multiplying by a power of 2.
reduce n/16 to lowest terms (cancel out common multiples of 2). I guess you need to compute the greatest common divisor. In Python that's fractions.gcd, dunno about C++.
I did what Jhecht said because it seemed easy to do with python dictionary.

Resources