The birthday paradox is a well-known phenomenon; two people share this special day that year, seemingly often, and we still get excited when it happens. Statistically speaking, the probability of meeting someone like this is really high, since in a room of just 23 people, the probability is already at 50%. While this may be an interesting fact, why is this introducing a section about hashing?
Birthdays can be considered a hash function—although a bad one. Hash functions are functions that map one value onto another value of a fixed size, like combining the day and month of a birthday into u64, shown as follows:
fn bd_hash(p: &Person) -> u64 {
format!("{}{}", p.day, p.month) as u64
}
This function will prove very ineffective indeed, shown as follows:
- It is very hard to find out someone's birthday deterministically without asking them
- The...