Assigning a random binary value to only a percentage of cells

hunnel

New Member
Joined
Mar 25, 2018
Messages
4
Hello,

I am struggling with this which should be seemingly simple.

How can I assign a random binary value to a percentage of identified cells?

I have a column that indicates which cells I want this binary value to be associated with. My problem is when trying to chose both a percentage and implementing a random element to it.

[TABLE="width: 500"]
<tbody>[TR]
[TD]Suvey ID[/TD]
[TD]Season[/TD]
[TD]Score[/TD]
[TD]Random Binary[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Peak[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Peak[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Off Season[/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Off Season[/TD]
[TD]8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Off Season[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Off Season[/TD]
[TD]8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Peak[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Within the random binary field I want to give 70% of those within the "Off Season" category a 1 and the remaining 30% a 0. For those in the "Peak Season" I would like to assign 30% a 1 and 70% a 0.

Any advice would be of great help!

Thank you,
Dan
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the Forum!

D2: =RAND()
E2: =0+(COUNTIFS(B$2:B$8,B2,D$2:D$8,"<="&D2)<=VLOOKUP(B2,B$11:C$12,2,))
C11: =ROUND(30%*COUNTIF(B$2:B$8,B11),0)
C12: =ROUND(70%*COUNTIF(B$2:B$8,B12),0)

(You may want to ROUNDUP or ROUNDDOWN instead)

<lookup(b2,{"off season","peak"},{0.5,0.5}))

Book1
ABCDE
1IDSeasonScoreHelper"Random"
21Peak00.8120
32Peak10.7581
43Off Season50.8711
54Off Season80.5231
65Off Season40.9790
76Off Season80.8931
87Peak40.8730
9
101's to allocate
11Peak1
12Off Season3
Sheet1
</lookup(b2,{"off>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,711
Members
453,748
Latest member
akhtarf3

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