Questions tagged [birthday-paradox]

The Birthday Paradox is a phenomenon in probability in which the probability of a population containing two individuals with the same property is much greater than would be intuitively expected. In its original form it describes the likelihood that any two individuals in a room share a birthday. Amongst other things, the Birthday Paradox affects cryptography, hashing and various applications of random number generators.

The Birthday Paradox is a phenomenon where two individual samples selected from a population may have the same value, for example the birthdays of individuals in a room. The paradox is that the probability of this coincidence happening is much higher than people expect. Amongst other things the phenomenon affects hashing, cryptography and various applications of random number generators.

Overview

The problem is originally defined as the probability of any two people in the room sharing the same birthday. The key point is that any two people in the room could share a birthday. People tend to naively misinterpret the problem as the probability of someone in the room sharing a birthday with a specific individual, which is the source of the cognitive bias that often causes people to underestimate the probability. This is the incorrect assumption – there is no requirement for the match to be to a specific individual and any two individuals could match.

This graph shows the probability of a shared birthday as number of people in the room increases. For 23 people, the probability of two sharing a birthday is just over 50%.

The probability of a match occurring between any two individuals is much higher than the probability of a match to a specific individual as the match does not have to be to a specific date. Rather, you only have to find two individuals that share the same birthday. From this graph (which can be found on the wikipedia page on the subject), we can see that we only need 23 people in the room for there to be a 50% chance of finding two that match in this way.

Some applications

  • Cryptographic hashing relies on the low probability of any two items having the same hash value. In order to achieve this the hash value must be very large so as to make it computationally infeasible to find another item that hashes to the same value. The Birthday paradox means that the width of the hash values must be very large in order for the probability of a collision to be sufficiently low.

  • In a Hash Table, the Birthday Paradox makes the likelihood of collisions quite high unless you have a perfect hash function that hashes a controlled set of source values to a unique set of hash values. In other cases, the hash table must be able to deal with relatively frequent collisions.

  • If you need a guaranteed unique sequence of random numbers, you cannot rely on simply generating random numbers, as the probability of a collision is quite high for relatively small sample sets. Instead, a set of unique numbers must be generated (perhaps just sequentially) and shuffled into a random order.

The tag is most applicable to questions about applications directly affected by the phenomenon (e.g. cryptographic hashing), or perhaps re-tagging a question where the poster has displayed obvious naievity about it.

57 questions
0
votes
0 answers

Is my approach valid for showing that my algorithm (usage of python's random.sample) is NOT susceptible to the Birthday Problem?

I tried to prove to myself one way or the other whether the way I was generating these "codes" was susceptible to the Birthday Problem, in which case--I tell myself--collisions should eventually grow with the square of the number of reserved codes,…
Brian Peterson
  • 2,800
  • 6
  • 29
  • 36
0
votes
2 answers

find probability of n people in a class of x share the same birthday using monte carlo simulation in java

As the problem states, i must use monte carlo(randomness) to solve the question given. I am running the simulation 1,000,000 times. import java.util.*; public class MonteCarlo { public static void main(String[] args) { Scanner sc = new…
rimvoo
  • 1
  • 1
0
votes
0 answers

How to deal with large numbers from specific range?

I have struggled with errors while modifying the below code to select numbers from specific range. // RANDOM NUMBERS: struct seed { uint256_t seed; uint128_t counter; }; /* * Create a new random seed. */ static struct seed…
0
votes
1 answer

How to Resolve For Loop Error While Running the Birthday Paradox

prob_matches = [] num_people = [2,80] def birthday_sim(num_people , num_sims = 1000): possible_birthdays = [i for i in range(0,365)] for party in range(num_sims): birthdays = pd.Series(random.choices(possible_birthdays,…
Marie B
  • 11
  • 5
0
votes
1 answer

Too frequent Random Byte Collision

I've written a program to simulate collisions in accordance to the typical "Birthday Problem". However, even taking that into account I'm seeing collisions happen far too frequently in the random data, to the point where my generator is reporting…
Eterm
  • 1,698
  • 12
  • 23
0
votes
3 answers

Speed up processing 32 bit numbers in combinations (k from n)

I have a list of 128 32 bit numbers, and I want to know, is there any combination of 12 numbers, so that all numbers XORed give the 32 bit number with all bits set to 1. So I have started with naive approach and took combinations generator like…
0
votes
2 answers

Monte Carlo simulation of Birthday paradox in python 3

The birthday paradox is that everyone has equal probability of having a birthday on any given of 365 days. We start adding people in a room. What is the probability that 2 people have birthdays on same day as a function of number of people in the…
user16116851
0
votes
1 answer

Generate small UID with uniqueness

I need to generate the UID (alphanumeric) for my use case but that should be a maximum of 7 characters long as we want UID to be random but manageable, like a PNR (CYB6KL) for example. Now if I am not wrong, I can generate a random UID that is…
Muhammad Umer
  • 363
  • 2
  • 8
  • 19
0
votes
1 answer

Java array problem regarding Birthday Paradox - details inside post. I have been unable to figure out what is wrong with my code and need assistance

Problem prompt Birthday problem. Suppose that people enter a room one at a time. How people must enter until two share a birthday? Counterintuitively, after 23 people enter the room, there is approximately a 50–50 chance that two share a birthday.…
Edward
  • 1
0
votes
0 answers

birthday probability program in Fortran 90

I have been given an assignment to create a Fortran 90 program that calculates how many people are needed so that the probability of two or more people having the same birthday becomes 90%. I would like to define variables as follows: P2 =…
user13559762
0
votes
1 answer

Birthday Paradox in Python with monte carlo method?

Trying to find the smallest # of people needed to "enter" a room to have a probability of at least 50% for two people sharing the same birthday, using the monte carlo method (the well known solution is 23 people, but I cant seem to find my errors in…
astralled
  • 21
  • 6
0
votes
1 answer

What is the general formula for calculating the probability of generating a duplicate random number?

I am generating random order tracking numbers that should be short, yet should not be duplicate. For a tracking number consisting of 3 digits, we will generate a duplicate random number after 40 attempts on average. If we bump it to 12 digits, it…
user6269864
0
votes
4 answers

Birthday paradox python - incorrect probability output

I am having issues with the programming the birthday paradox in Python. The birthday paradox basically says that if there are 23 people in a class, the probability that two of them will have the same birthday is 50%. I have attempted to code this…
Alcor
  • 43
  • 1
  • 5
0
votes
2 answers

My birthday paradox event simulator in javascript is not working well

I tried to do a in Javascript a birthday paradox event for 23 students, it should give me an average probability of 51% but it always give me number around 67%. Here the code: var pers = []; var D = 0; for (var i = 0; i < 10000; i++) { for (var…
0
votes
1 answer

How many samples needed for a collision (birthday paradox)

Just trying to understand birthday paradox. Using a following code I figured out that I need on average 12 samples to get a birthday collision. Can not understand why it is much lower than normal 23 people to get a 1/2 chance of a birthday…