Excel problem

I want to generate random numbers in order to do a simulation.For example, let's say we have 20 cats 80 dogs. How can i have different combinations of those numbers? The function "rand" can generate 0-1 for x times.But I do not know how to generate only 20 "0" and only 80 "1"

6 Comments
 

I'm not sure if I understand exactly what you want to do, but couldn't yo do something like this:

Where A1 =RANDBETWEEN(0,100)

And B1 = 100-A1

 

This is actually non-trivial and an interesting question. I am sure there are better ways of doing this but:

Fill 100 columns and 100 rows (all 10,000 cells) with "=if(rand()0.8,0,1)" Fill row 101 with sums of above 100 cells Use index function to find column in which the first 20 appears in the 101st row In Column 101, use offset function, with argument from above, to read the values from that particular column

That will get you an answer in probably 80% of the time. If you want it in more % of the time, increase number of columns or decrease number of rows/specifications.

Hope that helps. I feel like I am missing a very obvious solution.

 

key here is that you want to preserve the probability ratio of selection. if you create a variable that returns 0 or 1 equally, then it simulates a population where you have 50 cats and 50 dogs. rand will give you what you need, you just have to deal with the output accordingly.

to get a random integer from 1 to 10, use =ROUND(RAND()*9,0)+1

then assign your outputs accordingly 1-8 = dogs, 9-10 = cats

=IF(ROUND(RAND()*9,0)+1=8,"Dog","Cat")

-- sm
 
Best Response

Better yet - to actually get results 100% of the time, pick 100 random numbers (in Column A), then in column B find the rank of each number in Column A (rank amongst all the numbers in Column A). Then in Column C, if the value in Column B is = 20, the Cat, otherwise Dog.

Of course, its not that easy. There is no function to rank a number in Excel, so either write one in VBA or synthetically replicate. Replicating is a bit tricky, though possible. Will require 200 columns of calculations - basically in each subsequent column, find the max of the previous column, and then eliminate that number from the set, and move the set over to the next column. Then use match function to determine at which point a number dropped out, and divide by 2. Done.

 

ah, missed the combination bit. agree with dr joe that rand and rank would be the easiest solution.

put 20 cats and 80 dogs in cells A1:A100

put =RAND() in cells B1:B100

insert VBA module

run this subroutine

Sub rand_n_rank() Range("B1:B100").Calculate Range("A1:B100").Sort Range("B1"), xlAscending End Sub

-- sm
 

Soluta quod est iste ad exercitationem consequuntur. Et libero aperiam nemo qui quisquam debitis. Consequatur est quisquam hic voluptatem vel laboriosam. Quo enim harum similique nulla modi optio autem. Sed harum dolores tempore doloribus.

Quae quis et id odit doloribus amet ipsum. Reprehenderit accusamus magni error sit quam sunt.

Odit accusantium esse atque totam aliquam eius. Fugit delectus illum unde architecto. Possimus qui dicta et aperiam. Ea dolor distinctio sint error cumque. Expedita doloremque voluptas esse eaque. Delectus magnam et placeat cumque blanditiis omnis sunt.

Itaque temporibus consequatur qui est magni. Ab quod aperiam ut est rerum ut. Quas vel in voluptas laboriosam nihil a. Temporibus nesciunt mollitia rerum nobis aperiam illum atque. Sint dicta ut mollitia hic ea molestiae vel quo.

Career Advancement Opportunities

July 2026 Investment Banking

  • Evercore 01 99.4%
  • Moelis & Company 01 98.9%
  • JPMorgan 01 98.3%
  • Guggenheim Partners 01 97.7%
  • Morgan Stanley 07 97.1%

Overall Employee Satisfaction

July 2026 Investment Banking

  • Moelis & Company No 99.4%
  • Evercore No 98.8%
  • Morgan Stanley 01 98.3%
  • BMO Capital Markets 12 97.7%
  • Banco Santander 01 97.1%

Professional Growth Opportunities

July 2026 Investment Banking

  • Evercore 01 99.4%
  • Moelis & Company 01 98.9%
  • Morgan Stanley 06 98.3%
  • Goldman Sachs 01 97.7%
  • JPMorgan 01 97.1%

Total Avg Compensation

July 2026 Investment Banking

  • Vice President (15) $434
  • Associates (46) $258
  • 3rd+ Year Analyst (8) $210
  • 2nd Year Analyst (22) $179
  • Intern/Summer Associate (13) $156
  • 1st Year Analyst (80) $150
  • Intern/Summer Analyst (73) $101
notes
16 IB Interviews Notes

“... there’s no excuse to not take advantage of the resources out there available to you. Best value for your $ are the...”

Leaderboard

1
redever's picture
redever
99.2
2
kanon's picture
kanon
99.0
3
Secyh62's picture
Secyh62
99.0
4
BankonBanking's picture
BankonBanking
99.0
5
Betsy Massar's picture
Betsy Massar
98.9
6
GameTheory's picture
GameTheory
98.9
7
DrApeman's picture
DrApeman
98.9
8
dosk17's picture
dosk17
98.9
9
CompBanker's picture
CompBanker
98.9
10
bolo up's picture
bolo up
98.8
success
From 10 rejections to 1 dream investment banking internship

“... I believe it was the single biggest reason why I ended up with an offer...”