SOLVED

Random number with condition

%3CLINGO-SUB%20id%3D%22lingo-sub-1480341%22%20slang%3D%22en-US%22%3ERandom%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1480341%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20I%20am%20trying%20to%20random%20number%20for%26nbsp%3B%2024%20hrs%20with%20below%20conditions%3A%3C%2FP%3E%3COL%3E%3CLI%3ENo%20number%20should%20be%20more%20than%20100.%3C%2FLI%3E%3CLI%3EThe%20Sum%20of%20all%20the%20numbers%20should%20be%201440.%3C%2FLI%3E%3C%2FOL%3E%3CP%3EThe%20requirement%20is%20the%20list%20should%20be%20fully%20random.%20In%20the%20%22method%20tried%22%20i%20have%20tried%20to%20do%20the%20same%20but%20can't%20achieve%20the%20first%20condition.%20Attaching%20the%20file.%20Need%20your%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3ESandip%20Gumtya%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1480341%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1480559%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1480559%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676571%22%20target%3D%22_blank%22%3E%40sandipgumtya%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20first%20observation%20is%20that%20a%20uniform%20distribution%20over%200-100%20will%20give%20an%20expected%20value%20of%201200%20and%20not%201440%2C%20so%20larger%20values%20must%20be%20more%20likely%20than%20smaller%20ones.%26nbsp%3B%20In%20the%20attached%2C%20I%20have%20increased%20random%20numbers%20in%20the%20region%20of%200.5%2C%20leaving%20the%20limits%20at%200.0%20and%201.0.%26nbsp%3B%20The%20extent%20to%20which%20the%20distribution%20is%20biased%20is%20determined%20once%20the%20specific%20set%20random%20values%20is%20known.%26nbsp%3B%3C%2FP%3E%3CP%3ENote%3A%20The%20form%20of%20the%20bias%20was%20chosen%20on%20the%20basis%20of%20computational%20convenience%20rather%20than%20rigour.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1480587%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1480587%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676571%22%20target%3D%22_blank%22%3E%40sandipgumtya%3C%2FA%3E%26nbsp%3B%20I%20like%20your%20method%20so%20I%20just%20tweaked%20it%20a%20little%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DB3-D3%2FSUM(D%3AD)*(SUM(B%3AB)-2*%24B%2427)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Einstead%20of%20multiplying%20the%20random%20number%20fraction%20by%20the%20total%20I%20multiplied%20it%20by%20the%20difference%20between%20the%20max%20sum%20and%20required%20total%20and%20then%20subtracted%20that%20from%20the%20individual%20max.%26nbsp%3B%20When%20the%20individual%20max%20are%20all%20the%20same%20it%20certainly%20equally%20random.%26nbsp%3B%20But%20if%20the%20individual%20max%20are%20not%20the%20same%20then%20you%20would%20need%20to%20have%20it%20proportional%20to%20the%20range%20of%20that%20individual%20compared%20to%20the%20total.%26nbsp%3B%20Is%20that%20something%20that%20you%20need%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1480659%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1480659%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHI%2C%20Thanks.%20This%20works.%20If%20the%20data%20is%20required%20to%20be%20populated%20for%20365%20days%20of%20the%20year%20with%20the%20same%20daily%20limits%20and%20conditions%2C%20what%20tweak%20is%20required%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1481255%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1481255%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20in%20a%20couple%20of%20cases%2C%20the%20series%20violates%20the%20max(100)%20permissible%20value.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1481292%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1481292%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F570951%22%20target%3D%22_blank%22%3E%40mtarler%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks.%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EIf%20the%20data%20is%20required%20to%20be%20populated%20for%20365%20days%20of%20the%20year%20in%20a%20single%20column%20with%20the%20same%20daily%20limits%20and%20conditions%2C%20what%20tweak%20is%20required%3F%20Is%20there%20a%20simpler%20approach%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1482788%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1482788%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677557%22%20target%3D%22_blank%22%3E%40sandipgumtya365%3C%2FA%3E%26nbsp%3B%20first%20off%20the%20more%20I%20thought%20about%20this%20problem%20the%20more%20I%20don't%20know%20if%20there%20is%20a%20'perfect'%20solution.%26nbsp%3B%20that%20said%20my%20last%20answer%20was%20technically%20correct%20as%20it%20has%20a%20max%20value%20of%20100%20but%20wrong%20because%20I%20assume%20you%20don't%20want%20any%20negative%20numbers%20either%20and%20in%20some%20cases%20a%20negative%20value%20can%20result.%26nbsp%3B%20so%20that%20said%20I%20have%20a%20new%20solution%20that%20I%20do%20believe%20(and%20based%20on%20testing)%20will%26nbsp%3B%20always%20be%20between%200%20and%20100%20and%20total%201440.%20%26nbsp%3B%3C%2FP%3E%3CP%3Eas%20for%20doing%20the%20whole%20year%20I%20wasn't%20sure%20how%20you%20wanted%20or%20have%20that%20set%20up.%26nbsp%3B%20In%20the%20attached%20example%20I%20have%20the%20hours%20just%20continue%20to%20count%20up%20and%20then%20another%20column%20that%20calculates%20the%20day%2C%20but%20other%20options%20could%20work.%3C%2FP%3E%3CP%3EAs%20for%20an%20explanation%20of%20what%20the%20solution%20is%20doing%2C%20I%20realized%20that%20if%20the%20sum%20of%20the%20Rnd%20numbers%20*%20100%20is%20more%20than%20the%201440%20then%20scaling%20them%20by%201440%2Fsum%20would%20be%20multiplying%20by%20less%20than%20100%20and%20hence%20always%20be%20acceptable.%26nbsp%3B%20So%20only%20if%20the%20sum%20of%20the%20Rnd%20numbers%20is%20%26lt%3B14.40%20is%20it%20a%20potential%20problem.%26nbsp%3B%20so%20I%20figured%20that%20a%20sum%20of%201440%20is%20an%20average%20of%200.6%26nbsp%3B%20so%20I%20figured%20if%20the%20sum%20%26lt%3B%2014.40%20(i.e.%20avg%20less%20than%200.6)%20then%20if%20I%20take%201-rnd%2F2%20then%20the%20avg%20will%20be%20%26gt%3B0.6%20and%20the%20problem%20will%20go%20away.%3C%2FP%3E%3CP%3EThe%20problem%20with%20that%20solution%20is%20that%20it%20does%201%2F2%20the%20'range'%20of%20the%20numbers%2C%20but%20you%20do%20have%20to%20give%20something%20up%20with%20additional%20constraints.%26nbsp%3B%20That%20said%20I%20created%20a%20slightly%20better%20version%20in%20column%20G%20where%20I%20check%20if%20%26gt%3B%3D14.4%20then%20use%20the%20normal%20fraction%2C%20if%20%26lt%3B%3D9.6%20then%20use%201-rnd%20(without%20the%20divisor)%2C%20and%20if%20between%20them%20use%20a%20divisor%20of%209.6%2Fsum%20to%20maximize%20the%20range.%20%26nbsp%3B%20This%20last%20part%20is%20important%20as%20most%20of%20the%20time%20the%20average%20appears%20between%20those%20numbers%20and%20hence%20you%20want%20to%20maximize%20that%20range.%26nbsp%3B%20That%20said%2C%20I%20bet%20if%20you%20think%20about%20it%20some%20more%20you%20could%20tweak%20a%20little%20more%20out%20of%20it%2C%20but%20this%20is%20pretty%20good.%3C%2FP%3E%3CP%3Enote%20this%20worksheet%20is%20starting%20to%20slowdown%20due%20to%20calculations%20but%20right%20now%20the%20sheet%20has%204%20columns%20of%20calculations%20(rnd%23%2C%201st%20try%2C%202nd%20try%20and%203rd%20try)%20but%20you%20can%20and%20should%20delete%202%20of%20those%20columns.%3C%2FP%3E%3CP%3EBest%20of%20luck.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1483044%22%20slang%3D%22en-US%22%3ERe%3A%20Random%20number%20with%20condition%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1483044%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F570951%22%20target%3D%22_blank%22%3E%40mtarler%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20a%20ton.%20This%20seems%20to%20solve%20the%20issue.%20I%20will%20try%20some%20other%20iterations%20with%20the%20same%20idea.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi All,

        I am trying to random number for  24 hrs with below conditions:

  1. No number should be more than 100.
  2. The Sum of all the numbers should be 1440.

The requirement is the list should be fully random. In the "method tried" i have tried to do the same but can't achieve the first condition. Attaching the file. Need your help.

 

 

Thanks

Sandip Gumtya

 

7 Replies
Highlighted

@sandipgumtya 

The first observation is that a uniform distribution over 0-100 will give an expected value of 1200 and not 1440, so larger values must be more likely than smaller ones.  In the attached, I have increased random numbers in the region of 0.5, leaving the limits at 0.0 and 1.0.  The extent to which the distribution is biased is determined once the specific set random values is known. 

Note: The form of the bias was chosen on the basis of computational convenience rather than rigour.

 

Highlighted

@sandipgumtya  I like your method so I just tweaked it a little:

=B3-D3/SUM(D:D)*(SUM(B:B)-2*$B$27)

instead of multiplying the random number fraction by the total I multiplied it by the difference between the max sum and required total and then subtracted that from the individual max.  When the individual max are all the same it certainly equally random.  But if the individual max are not the same then you would need to have it proportional to the range of that individual compared to the total.  Is that something that you need?

Highlighted

@Peter Bartholomew 

HI, Thanks. This works. If the data is required to be populated for 365 days of the year with the same daily limits and conditions, what tweak is required?

Highlighted

@Peter Bartholomew 

Also in a couple of cases, the series violates the max(100) permissible value.

Highlighted

@mtarler 

Thanks.

If the data is required to be populated for 365 days of the year in a single column with the same daily limits and conditions, what tweak is required? Is there a simpler approach?

Highlighted
Best Response confirmed by sandipgumtya (Occasional Contributor)
Solution

@sandipgumtya365  first off the more I thought about this problem the more I don't know if there is a 'perfect' solution.  that said my last answer was technically correct as it has a max value of 100 but wrong because I assume you don't want any negative numbers either and in some cases a negative value can result.  so that said I have a new solution that I do believe (and based on testing) will  always be between 0 and 100 and total 1440.  

as for doing the whole year I wasn't sure how you wanted or have that set up.  In the attached example I have the hours just continue to count up and then another column that calculates the day, but other options could work.

As for an explanation of what the solution is doing, I realized that if the sum of the Rnd numbers * 100 is more than the 1440 then scaling them by 1440/sum would be multiplying by less than 100 and hence always be acceptable.  So only if the sum of the Rnd numbers is <14.40 is it a potential problem.  so I figured that a sum of 1440 is an average of 0.6  so I figured if the sum < 14.40 (i.e. avg less than 0.6) then if I take 1-rnd/2 then the avg will be >0.6 and the problem will go away.

The problem with that solution is that it does 1/2 the 'range' of the numbers, but you do have to give something up with additional constraints.  That said I created a slightly better version in column G where I check if >=14.4 then use the normal fraction, if <=9.6 then use 1-rnd (without the divisor), and if between them use a divisor of 9.6/sum to maximize the range.   This last part is important as most of the time the average appears between those numbers and hence you want to maximize that range.  That said, I bet if you think about it some more you could tweak a little more out of it, but this is pretty good.

note this worksheet is starting to slowdown due to calculations but right now the sheet has 4 columns of calculations (rnd#, 1st try, 2nd try and 3rd try) but you can and should delete 2 of those columns.

Best of luck.

Highlighted

@mtarler 

Thanks a ton. This seems to solve the issue. I will try some other iterations with the same idea. 

 

 

Thanks