Generate Random Binary Number within specific requirement i.e. percentage etc.

AweSome15

New Member
Joined
Aug 23, 2021
Messages
4
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello everyone,
I wrote formula to generate binary number (0,1), as obviously it had generated as I expected (as can be seen). My questions are:
1. How can I formulate, whenever it generated '0', it would stay for at least/minimum two rows (included the generated number), but when it generated '1' it would stay for at least five rows (included the generated number). Whatever number after the minimum requirement fulfilled will be ignored
2. Is it possible to generate binary number (0,1) (as i pointed out in the 1st question) while adding another requirement i.e., the '0' or '1' number within specific percentage (let say 20 %) and the rest will automatically follows on the portion to it.

Most appreciated to all of you,
Cheers Up


=RANDBETWEEN((0,1)Expected=RANDBETWEEN((0,1)Expected
0011
1011
0011
1111
1111
1111
0100
1100
1100
1100
0000
1011
1101
% of Zeros
38.46%​
% of Zeros
38.46%​
% of non-Zeroes
61.54%​
% of non-Zeroes
61.54%​
 
About the secont part of your question:
You will need a code finding such numbers or a setup similar to the one below (I made it for 30% Zeros because 20% is quite low and may require a lot of space to find one):
Cell Formulas
RangeFormula
G6:T35G6=IF(OR(COUNTIF(G1:G5,1)=5,COUNTIF(G4:G5,0)=2,ISBLANK(G5)),RANDBETWEEN(0,1),G5)
G37:T37G37=COUNTIF(G6:G35,0)/COUNT(G6:G35)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G37:AC37Cell Value<=$F$37textNO
Hi, Bob
Thanks for the reply.... :)
What i mean is, what ever binary numbers generated in the A column, while still fulfilling the requirement of what I previously explained. So, I can either select the exact percentage of '0' or '1' in the B column. Let's say, i would select the '0' for 40% of fifty generated-number (A2:A51), so the total number of '0' would be twenty of zeroes number of which arranged at least/minimum two rows in a series.

Hope this clarify my problem statement
Many Thanks
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Sorry, I stand corrected. The previous formula will always get you started with a Zero.
Try this one:
=IF(OR(COUNTIF(A1:A5,1)=5,COUNTIF(A4:A5,0)=2,ISBLANK(A5)),RANDBETWEEN(0,1),A5)
FramesScan.xlsm
ABCD
1
2
3
4
5
610:923.08%
711:3076.92%
81tot:39
91
101
111
120
130
140
151
161
171
181
191
200
210
221
231
241
RAND
Cell Formulas
RangeFormula
D6D6=C6/C8
D7D7=C7/C8
C6C6=COUNTIF(A:A,0)
C7C7=COUNTIF(A:A,1)
C8C8=COUNT(A:A)
A6:A24A6=IF(OR(COUNTIF(A1:A5,1)=5,COUNTIF(A4:A5,0)=2,ISBLANK(A5)),RANDBETWEEN(0,1),A5)
I have tried this formula, but still not of what I expected yet. I realized that you started from the 6th row since the formula needs a reference. Yes, its okay if it starts from zero ('0') as default initialization.

Most appreciated to you,
Thanks
 
Upvote 0
Hi, EartWorm really appreciated for the reply.
Sorry, i still could not use XL2BB function. So please take a look for the screenshot. So the idea is by running the RAND function to generate random binary numbers (lets say 50 numbers from A2:A51), then the expected result next to it (B2:B51), under conditions of:
1. If it generates '1' (A2) then it will stay for at least five rows in total (B2:B6), and when it generates '0' (A6) then it will stay for at least two rows (B7:B8)
2. What ever number after the requirement is fulfilled (B14:B15), what ever number next to it if the same the previous (0 at A:16) it would be stayed otherwise has to stop due to change (1 at A:17). Thus, it will fulfill the requirement as mentioned in the 1st.

I hope this may clarify my problem statement :D

View attachment 45511
Looks simple but not easy . let me do some experiments
 
Upvote 0
This is next to impossible because there is no fixed pattern .
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,954
Members
449,198
Latest member
MhammadishaqKhan

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