mercredi 27 janvier 2016

What does these number in random no. generator do?

Basically i understand the program but not the math/numbers used here.

import random

def r_int():
  x = int(abs(10 * random.random() % 20))
  return x

I figured out this is equivalent to random.randint(0,9). What does the % and 20 do here?




Aucun commentaire:

Enregistrer un commentaire