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%​
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Still not clear . Please highlight the result that you require and share excel file.
 
Upvote 0
The thing with volatile functions is that they recalculate on each change in the workbook. I don't think it is easily doable without code.
Plus the idea of random is to be random
 
Upvote 0
The thing with volatile functions is that they recalculate on each change in the workbook. I don't think it is easily doable without code.
Plus the idea of random is to be random

I don't see a pattern in your data.
 
Upvote 0
Try this formula in A6 (starting not earlier than row 6 - you will need 5 cells above for the range in the formula):
Excel Formula:
=IF(OR(COUNTIF(A1:A5,1)=5,COUNTIF(A4:A5,0)=2),RANDBETWEEN(0,1),A5)
 
Upvote 0
Do
Try this formula in A6 (starting not earlier than row 6 - you will need 5 cells above for the range in the formula):
Excel Formula:
=IF(OR(COUNTIF(A1:A5,1)=5,COUNTIF(A4:A5,0)=2),RANDBETWEEN(0,1),A5)
Do you want to count the combination of 01 and 10 only ? based on data data being entered above ?
 
Upvote 0
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)
 
Upvote 0
Please share the sample and manually highlighted the result that you require for more clear understanding.
 
Upvote 0
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
 
Upvote 0
Please share the sample and manually highlighted the result that you require for more clear understanding.
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

ASK_HELP2.png
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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