1

What are use cases to hand over different numbers in random.seed(0)?

import random
random.seed(0)
random.random() 

For example, to use random.seed(17) or random.seed(9001) instead of always using random.seed(0). Both return the same "pseudo" random numbers that can be used for testing.

import random
random.seed(17)
random.random() 

Why dont use always random.seed(0)?

Rene B.
  • 6,557
  • 7
  • 46
  • 72
  • 2
    For testing `0` is fine. For production you need to use a seed generated from a good source of entropy. There have been countless breaches from people using a fixed seed of something like time as a seed allowing the numbers to be predicted by an attacker. – Boris the Spider Dec 30 '18 at 09:24
  • Relevant: https://stackoverflow.com/a/47515179/476 – deceze Dec 30 '18 at 09:46

2 Answers2

1

The seed is saying "random, but always the same randomness". If you want to randomize, e.g. search results, but not for every search you could pass the current day.

If you want to randomize per user you could use a user ID and so on.

shredding
  • 5,374
  • 3
  • 46
  • 77
1

An application should specify its own seed (e.g., with random.seed()) only if it needs reproducible "randomness"; examples include unit tests, games that display a "code" based on the seed to players, and simulations. Specifying a seed this way is not appropriate where information security is involved. See also my article on this matter.

Peter O.
  • 32,158
  • 14
  • 82
  • 96