The birthday paradox in probability theory asks what is the probability that in a set of n randomly chosen people, at least two of them share the same birthday. It is referred to as a paradox because many people wouldn't believe it when you hear the answer. In a room of 23 randomly chosen people, the probability that at least two of them share the same birthday is around 50%! Can you believe it? So even in smaller classes at SBU, the probability that at least two people share the same birthday is close to 100%! Instead of expecting you to simply accept this conclusion, we will be doing a little experiment to convince you that it's valid. Complete the function birthday_paradox, which takes one parameter, num_students, the number of students in a room. The function generates num_students random integers in the range [1, 365] and returns False if the values are all unique, or True if there is at least one duplicated value. As num_students increases, the likelihood that there is at least one duplicated value also increases, and rather quickly, at that! Hint: You can use the function set ( ) to take a list and create a copy that contains only the unique values. For example: x = [1, 2, 3, 3] y = set (x) Then y will be {1, 2, 3}. (The use of curly braces indicates that we have a set, a collection of unique values.) Consider what information you can glean (and what conclusions you can draw) by looking at the length of this new list. Note For experiments involving random values, it can be difficult to give examples of expected output. For this part, Colab will call your function many times to perform many simulations, and then report the average outcome. Your results may not exactly match the expected outcomes, but they should be "close". [ ] 1 import random 2 3 def birthday_paradox (num_students): 4 5 6 7 # Do not edit anything below this line 8 def birthday_trials (num_students, num_trials): 9 10 11 12 13 14 15 # Test cases # should be approx. 0.12 # should be approx. 0.51 16 print (birthday_trials (10, 10000)) 17 print (birthday_trials (23, 10000)) 18 print (birthday_trials(5, 10000)) # should be approx. 0.025 19 print (birthday_trials (100, 10000)) # should be approx. 1.0 20 return 0 # DELETE THIS LINE and start coding here. # Remember: end all of your functions with a return statement, not a print statement! same_birthday = 0 for i in range(num_trials): if birthday_paradox (num_students): same_birthday += 1 return same_birthday / num_trials

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
The birthday paradox in probability theory asks what is the probability that in a set of n randomly chosen people, at least two of them share the
same birthday.
It is referred to as a paradox because many people wouldn't believe it when you hear the answer. In a room of 23 randomly chosen people, the
probability that at least two of them share the same birthday is around 50%! Can you believe it? So even in smaller classes at SBU, the
probability that at least two people share the same birthday is close to 100%!
Instead of expecting you to simply accept this conclusion, we will be doing a little experiment to convince you that it's valid. Complete the
function birthday_paradox, which takes one parameter, num_students, the number of students in a room. The function generates
num_students random integers in the range [1, 365] and returns False if the values are all unique, or True if there is at least one duplicated
value. As num_students increases, the likelihood that there is at least one duplicated value also increases, and rather quickly, at that!
Hint: You can use the function set () to take a list and create a copy that contains only the unique values. For example:
x = [1, 2, 3, 3]
y = set (x)
Then y
will be {1, 2, 3}. (The use of curly braces indicates that we have a set, a collection of unique values.) Consider what information you
can glean (and what conclusions you can draw) by looking at the length of this new list.
Note
For experiments involving random values, it can be difficult to give examples of expected output. For this part, Colab will call your function many
times to perform many simulations, and then report the average outcome. Your results may not exactly match the expected outcomes, but they
should be "close".
[ ]
1 import random
2
3 def birthday_paradox (num_students):
4
5
6
7 # Do not edit anything below this line
8 def birthday_trials (num_students, num_trials):
9
10
11
12
13
14
15 # Test cases
16 print (birthday_trials (10, 10000)) # should be approx. 0.12
17 print (birthday_trials (23, 10000))
# should be approx. 0.51
# should be approx. 0.025
18 print (birthday_trials(5, 10000))
19 print (birthday_trials (100, 10000))
20
# should be approx. 1.0
return 0 # DELETE THIS LINE and start coding here.
# Remember: end all of your functions with a return statement, not a print statement!
same_birthday = 0
for i in range(num_trials):
if birthday_paradox (num_students):
same_birthday += 1
return same_birthday / num_trials
Transcribed Image Text:The birthday paradox in probability theory asks what is the probability that in a set of n randomly chosen people, at least two of them share the same birthday. It is referred to as a paradox because many people wouldn't believe it when you hear the answer. In a room of 23 randomly chosen people, the probability that at least two of them share the same birthday is around 50%! Can you believe it? So even in smaller classes at SBU, the probability that at least two people share the same birthday is close to 100%! Instead of expecting you to simply accept this conclusion, we will be doing a little experiment to convince you that it's valid. Complete the function birthday_paradox, which takes one parameter, num_students, the number of students in a room. The function generates num_students random integers in the range [1, 365] and returns False if the values are all unique, or True if there is at least one duplicated value. As num_students increases, the likelihood that there is at least one duplicated value also increases, and rather quickly, at that! Hint: You can use the function set () to take a list and create a copy that contains only the unique values. For example: x = [1, 2, 3, 3] y = set (x) Then y will be {1, 2, 3}. (The use of curly braces indicates that we have a set, a collection of unique values.) Consider what information you can glean (and what conclusions you can draw) by looking at the length of this new list. Note For experiments involving random values, it can be difficult to give examples of expected output. For this part, Colab will call your function many times to perform many simulations, and then report the average outcome. Your results may not exactly match the expected outcomes, but they should be "close". [ ] 1 import random 2 3 def birthday_paradox (num_students): 4 5 6 7 # Do not edit anything below this line 8 def birthday_trials (num_students, num_trials): 9 10 11 12 13 14 15 # Test cases 16 print (birthday_trials (10, 10000)) # should be approx. 0.12 17 print (birthday_trials (23, 10000)) # should be approx. 0.51 # should be approx. 0.025 18 print (birthday_trials(5, 10000)) 19 print (birthday_trials (100, 10000)) 20 # should be approx. 1.0 return 0 # DELETE THIS LINE and start coding here. # Remember: end all of your functions with a return statement, not a print statement! same_birthday = 0 for i in range(num_trials): if birthday_paradox (num_students): same_birthday += 1 return same_birthday / num_trials
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education