# Python NumPy For Your Grandma - 3.7 random In this section, we’ll see how you can use NumPy's [random module](https://numpy.org/doc/stable/reference/random/index.html) to shuffle arrays, sample values from arrays, and draw values from a host of probability distributions. And then we'll see why everything I just showed you is deprecated, and how to updated it to modern standards. Let's see an example of how you might simulate rolling a 6-sided die 3 times. In other words, we want to draw three integers from the range 1 to 6, with replacement. For this we can use the `randint()` function from NumPy’s random module. ```python import numpy as np np.random.randint(low=1, high=7, size=3) ## array([6, 3, 1]) ``` If you try running this on your machine, you'll probably get something different. However, we can get reproducible results by setting a random number seed immediately before we generate random numbers. To set a seed, use the `seed()` function with your favorite value passed in. Try this example on your machine and you should get the same result. ```python np.random.seed(123) np.random.randint(low=1, high=7, size=3) ## array([6, 3, 5]) ``` Now, what if we wanted to draw three values between 1 and 6 without replacement? For this we can use the [`choice()`](https://numpy.org/doc/stable/reference/random/generated/numpy.random.choice.html) function, giving it - a 1d array of values to choose from - the number of samples we want to draw, whether values should be replaced which is `False` by default - and a 1d array of probabilities corresponding to our 1d array of options, which by default gives equal probability to each option. `choice()` is like a generalized version of `randint()`. Let’s see some examples. First we’ll draw 3 ints between 1 and 6 without replacement. ```python np.random.seed(2357) np.random.choice( a = np.arange(1, 7), size = 3, replace = False, p = None ) ## array([6, 5, 1]) ``` Next we’ll do the same thing, but we’ll give a probability to each element. ```python np.random.choice( a = np.arange(1, 7), size = 3, replace = False, p = np.array([0.1, 0.1, 0.1, 0.1, 0.3, 0.3]) ) ## array([5, 2, 6]) ``` Lastly we’ll draw 3 elements from an array of strings ```python np.random.choice( a = np.array(['you', 'can', 'use', 'strings', 'too']), size = 3, replace = False, p = None ) ## array(['use', 'you', 'can'], dtype='