4

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

In the end, both the probabilities and the position of the 1s will be random. That is proving hard to debug however.

The probabilities are currently distributed according to a 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 realise this may be naive, but I've honestly got no idea how random numbers are generated. How do I make these probabilities the same each time I run the test?

2
  • 1
    Seed the random number generator? Like numpy.random.seed(42)? Commented Nov 26, 2013 at 14:33
  • You might want to check the second answer in the linked question, he suggests using RandomState over just .seed() and explains in the comments. Commented Nov 26, 2013 at 14:35

2 Answers 2

3

Call

numpy.random.seed(x)

where x is a constant, and you will have same random samples every time you run the program.

Sign up to request clarification or add additional context in comments.

Comments

3

You can "seed" the random number generator to make it generate the same numbers on each run.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.