Reputation: 3
I am using numpy random generator to generate a number from (0,1)
with
np.random.uniform(0,1)
I can't find a way to seed a number and still keep it uniformly and randomly chosen from 0
to 1
.
I am also desperately new at coding.
Upvotes: 0
Views: 75
Reputation: 74172
I personally would recommend creating a new numpy.random.RandomState
object rather than using np.random.seed
. For example:
import numpy as np
rs = np.random.RandomState(0)
x = rs.randn(10)
will give an equivalent result to:
np.random.seed(0)
x = np.random.randn(10)
However the first method is much more explicit and makes it easier to keep track of the RNG state, for example in cases where you need multiple random number generators with different internal states.
Upvotes: 4
Reputation: 4118
If you want to set the seed for the generator use numpy.random.seed
.
Upvotes: 2