NumPy Tutorial NumPy Statistics NumPy References

NumPy - random.seed() function



The NumPy random.seed() function is used to seed the generator. This method is called when RandomState is initialized. It can be called again to re-seed the generator.

Syntax

numpy.random.seed(seed=None)

Parameters

seed Optional. Specify seed for RandomState. Must be convertible to 32 bit unsigned integers. int or 1-d array_like.

Example:

In the example below, random.seed() function is used to seed the generator. When seed is provided, it preserves the result and hence making it feasible to reproduce the result.

import numpy as np

#providing seed
np.random.seed(10)

#generating pseudo normally 
#distributed random numbers
x = np.random.normal(size=(3,3))

#printing x
print(x)

The output of the above code will be:

[[ 1.3315865   0.71527897 -1.54540029]
 [-0.00838385  0.62133597 -0.72008556]
 [ 0.26551159  0.10854853  0.00429143]]

❮ NumPy - Random