Cryptographically strong random numbers

Steven D'Aprano steve at pearwood.info
Fri Oct 16 12:25:03 EDT 2015


Hello folks,


Over on the Python-Dev mailing list there is an argument going on about PEP
506, the "secrets" module, for generating crypto random numbers and tokens.

If you have written crypto code that needs random numbers as described
below, I am looking for your feedback.

Python-Dev is arguing about which of the following three functions should be
included:

randbelow(end):
    return a random integer in the half-open interval 0...end
    (including 0, excluding end)

randint(start, end):
    return a random integer in the closed interval start...end
    (including both start and end)

randrange([start=0,] end [, step=1]):
    return a random integer in the half-open range(start, stop, step)


It has been claimed that most applications of crypto random numbers will
only need to generate them in the half-open range 0...end (excluding end).
If you have experience with using crypto random numbers, do you agree?
Which of the three functions would you use?


Please note that nothing will change about the random module and it's API.
If you are worried that random.randint will be removed, or
random.randrange, don't be concerned, that is completely off the cards.
This discussion is purely about what will be offered in the "secrets"
module.

https://www.python.org/dev/peps/pep-0506/


-- 
Steven




More information about the Python-list mailing list