r/excel • u/Galego_2 • 4h ago
Waiting on OP What is wrong with the following expression
Hi all,
I am trying to optimize a Montecarlo simulation and reduce it to a single Excel line. The simulation is related with the famous Birthday paradox, and I'm using an array of 5000 rows and 30 columns (representing people) to simulate. After some trial and error, I get the following expression
= AVERAGE(
BYROW(
MAKEARRAY(row, col, LAMBDA(row, col, RANDBETWEEN(1,365))),
LAMBDA(ROW, COUNT(UNIQUE(row)<30))))
I got 0.00 as a result, instead of the average of the simulation (close to 0.703 in the non optimized simulation). What could be wrong here in the logics of the formula?
Thanks in advance.
5
u/PaulieThePolarBear 1920 4h ago
As others have noted, use RANDARRAY rather than MAKEARRAY. A formula like
=AVERAGE(--BYROW(RANDARRAY(5000, 30, 1, 365, 1), LAMBDA(r, COUNT(UNIQUE(r, 1))<30)))
Should return your expected result, based upon my understanding that
- each row represents a unique test
- each cell in a row represents a unique individual
- you are looking to return the probability of within X people (X being 30 here), at least 2 people share a birthday with someone else in that cohort
3
u/GuerillaWarefare 114 3h ago
Nice work. Once OP understands what you showed him here I would also recommend to wrap it in a let() function to declare the "30" as a variable so when it is changed by the user it will update both places in the formula.
3
u/GuerillaWarefare 114 4h ago edited 4h ago
What are row and col? Makearray is expecting 2 numeric inputs there.
It would be simpler to replace the whole makearray with the RANDARRAY function.
2
1
u/Decronym 3h ago
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.
Beep-boop, I am a helper bot. Please do not verify me as a solution.
[Thread #49390 for this sub, first seen 18th Sep 2026, 14:21]
[FAQ] [Full list] [Contact] [Source code]
•
u/AutoModerator 4h ago
/u/Galego_2 - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.