# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Explain the use of seeds in generating pseudorandom numbers.
#
# # Seeds

# ### numpy.random.RandomState
#
# The data generation functions in numpy.random use a global random seed. To avoid
# global state, you can use numpy.random.RandomState to create a random number
# generator isolated from others
#
# numpy.random.RandomState is a container for the Mersenne Twister pseudo-random number generator.
#
# A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG),[1] is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. 

import numpy as np

rng = np.random.RandomState(1234)
rng.randn(10)

# ### numpy.random.seed
#
# This method is called when RandomState is initialized. 

# If you set the np.random.seed(a_fixed_number) every time you call the numpy's other random function, the result will be the same:

# np.random.seed(0) makes the random numbers predictable
np.random.seed(0)
np.random.rand(4)

# +
# np.random.seed(0) makes the random numbers predictable

np.random.seed(0)
np.random.rand(4)
# -

# ### Use random seed and shuffle method together

# +
numbers = [10, 20, 30, 40, 50, 60]
print ("Original list: ", numbers )

np.random.seed(4)
np.random.shuffle(numbers)
print("Reshuffled list ", numbers)

numbers = [10, 20, 30, 40, 50, 60]
np.random.seed(4)
np.random.shuffle(numbers)
print("reshuffled list ", numbers)
# -

# Reference:
#
# https://en.wikipedia.org/wiki/Mersenne_Twister
#     
# https://en.wikipedia.org/wiki/Pseudorandom_number_generator
#
# https://pynative.com/python-random-seed/



StarcoderdataJupyterScriptsDedupFiltered