import numpy.random # We can also import code from scipy to calculate binomial coefficients and # factorials. NOTE: you don't need this for the birthday simulation code in Task # 2.1, I just mention it here because you can use it to calculate the numerical # values for the questions in section 1. from scipy.special import binom, factorial # binom(n, k) computes "n choose k": print(binom(3, 1)) print(binom(4, 2)) # factorial(n) computes n! print("5! =", factorial(5)) print("10! =", factorial(10)) # numpy.random.randint(low, high) returns a random integer n such that low <= n < high print(numpy.random.randint(1, 100)) print(numpy.random.randint(1, 3)) # We can generate many at once by passing a third size parameter. It will # then return an array with that many random numbers. mynums = numpy.random.randint(1, 100, size=5) print(mynums) print("mynums has %d elements" % len(mynums)) print(mynums[2]) morenums = numpy.random.randint(1, 2, size=5) # Notice they must all be =1, since each returned n will satisfy 1 <= n < 2 print(morenums) ### WARNING WARNING WARNING ### # There is also a random.randint(low, high) function in the default python # library which returns random integers such that low <= n <= high. (whereas # numpy's version requires < high instead). So, be mindful of which version you # are using and the differences! ###############################