Formula for random yes or no, with fixed % of yes and no

elmacay

Board Regular
Joined
May 4, 2006
Messages
88
Hi all,

I'm looking for a formula for two things. The first is that I want to return a random yes or no for any record, based on a certain percentage of yes's. So for a 100 records, with that yes variable at 10%, I'd like to get exactly 10 times yes and 90 times no.

Then, for the 10% yes's, I'd like to return a random number between 1 and 12, and if possible with an exact proportion of 1/12 for each, although with the number of records, that won't be statistically significant.

The background is that there are 7,000 social housing apartments rented out, of which 10% of tenants will move out yearly, randomly divided over the 12 months.

Any help is greatly appreciated!

Cheers, elmacay
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Part 1:

A​
B​
C​
1​
Pct
10%​
B1: Input
2​
Rows
20​
B2: =ROWS(B5:B24)
3​
Yeses
2​
B3: =B1*B2
4​
Item
Result
5​
1​
No​
B5: =IF(RAND() < ($B$3 - COUNTIF(B$4:B4, "Yes")) / ROWS(B5:B$24), "Yes", "No")
6​
2​
No​
7​
3​
No​
8​
4​
Yes​
9​
5​
No​
10​
6​
No​
11​
7​
No​
12​
8​
No​
13​
9​
No​
14​
10​
No​
15​
11​
No​
16​
12​
No​
17​
13​
No​
18​
14​
No​
19​
15​
No​
20​
16​
No​
21​
17​
Yes​
22​
18​
No​
23​
19​
No​
24​
20​
No​

I don't understand Part 2.
 
Upvote 0
Consider the following. Assuming 1200 houses

Formulas
CellFormula
B1=ROUNDDOWN(COUNT(B2:B1201)*0.1,0)
C1=ROUNDDOWN(B1/12,0)

Values
CellValue
D10
E21

Formulas to copy down
CellFormula
B2=RAND()
C2=INDEX($A$2:$A$1201,RANK(B2,$B$2:$B$1201))
D2=IF(D1<$B$1,D1+1,"")
E3=IF(D3<>"",IF(COUNTIF($E$2:E2,E2)<$C$1,E2,E2+1),"")


In column C you have the house and in column E the month:

Excel Workbook
ABCDE
1LIST120.000100Month
2House10.21743826House93811
3House20.79717274House23721
4House30.07240526House111531
5House40.88980084House11441
6House50.14352507House102851
7House60.43779275House67761
8House70.34696654House79471
9House80.8577083House15781
10House90.46657688House64291
11House100.5228115House579101
12House110.38052232House756112
13House120.38370236House749122
14House130.24314565House912132
15House140.00874328House1184142
108House1070.2854487House86310711
109House1080.47592046House63610811
110House1090.98669431House1110911
111House1100.81205319House22011011
112House1110.41658899House71611112
113House1120.49668822House60511212
114House1130.67130158House40211312
115House1140.72468806House33511412
116House1150.8429541House17611512
117House1160.55480391House54511612
118House1170.87106914House13811712
119House1180.54412287House55711812
120House1190.03514036House115311912
121House1200.73333774House31712012
Hoja4




Check the example in the file
https://www.dropbox.com/s/9t993u24omavia1/house.xlsx?dl=0
 
Upvote 0
=IF(RAND() < ($B$3 - COUNTIF(B$4:B4, "Yes")) / ROWS(B5:B$24), "Yes", "No")

That guarantees no more than B3 number of "yes" values.

It does not guarantee exactly B3 number of "yes" values.

The following is one example where there are no "yes" values. In fact, in one set of 2000 trails, the results were:

yes=0: 254 no=20: 254
yes=1: 954 no=19: 954
yes=2: 792 no=18: 792
total=2000
0.718750 sec

So it failed to produce exactly two "yes" values 60% of the time.


BCDE
110%
220
32
4
5IF(C < D,"yes","no")<d,"yes","no")< td=""></d,"yes","no")<>rand(B3-COUNTIF)/B2
6no0.7825080.100000B6: =IF(C6<d6,"yes","no")< td=""></d6,"yes","no")<>
7no0.6787490.100000C6: =RAND()
8no0.5738050.100000D6: =($B$3-COUNTIF($B$5:B5,"yes"))/$B$2
9no0.1777240.100000
10no0.1342760.100000
11no0.5523240.100000
12no0.7530780.100000
13no0.3551380.100000
14no0.2077820.100000
15no0.8551790.100000
16no0.8180340.100000
17no0.2542400.100000
18no0.7907290.100000
19no0.4462690.100000
20no0.5091620.100000
21no0.5750070.100000
22no0.3750100.100000
23no0.4543310.100000
24no0.6412690.100000
25no0.5657690.100000

<tbody>
</tbody>
 
Last edited:
Upvote 0
Aarrgghh ! This forum mangles lines that have " < " without spaces around it. I fixed B5, but I didn't see E6 until it was too late to edit. I should be:
B6: =IF(C6 < D6, "yes", "no")
 
Upvote 0
That guarantees no more than B3 number of "yes" values.

It does not guarantee exactly B3 number of "yes" values.

I don't know what you did, but I would happily wager $1000 to your favorite charity that what I did gives exact results.
 
Upvote 0
I don't know what you did, but [...] what I did gives exact results.

Yes, my bad! I did not notice the relative reference in your ROWS(B5:B$24). So if we get to B23 and there are zero "yes" values, we will have RAND() < 1, which is TRUE. And if we get to B24 and there is only one "yes" value, again we will have RAND() < 1.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top