Python Wiki
Advertisement

This is a core module in Python


The random module is a module specific to many programming languages, including Python. It is used to generate random items from variables, be it from ranges, lists, tuples, etc. Currently, it uses the Mersenne Twister PRNG. The only functions that are important are getrandbits, random, shuffle, seed and randint.

Most important functions[]

  • random.getrandbits(bits) - return bits of randomness
  • random.random() - return a random decimal number >= 0.0 but <= 1.0
  • random.shuffle(dict) - shuffle a dict and return the shuffled version
  • random.seed(seed) - seed the PRNG with seed, useful for debugging only, the PRNG is usually auto-seeded
  • random.randint(min, max) - return a random integer >= min but <= max
Advertisement