Creating the same probability distribution for each test run

I am testing an algorithm that has random inputs: for reference, the inputs are a sequence of floating point numbers, buttoned together with some 0s and 1s (there are relatively few of them 1).

In the end, both the probabilities and position 1s will be random. However, it is difficult to debug.

Probabilities are currently distributed according to the Dirichlet distribution:

import numpy.random as ran

N=1024
num_ones = 10
probs = ran.dirichlet([1]*N)
probs = num_ones*probs
probs = probs
probs = sorted(probs, reverse=True)

I understand that this may be naive, but I honestly did not know how random numbers are generated. How can I make these probabilities the same every time I run the test?

+4
source share
2 answers

Call

numpy.random.seed(x)

x , .

+3

"" , .

numpy.random.seed(123) # change the seed for different tests
+3

All Articles