This module, while not part of the math set, is important because it makes random numbers that are cryptographically secure. Thus, we will look at how this module differs from the random module.
SystemRandom
class is the same as therandom.SystemRandom
class, that is, it provides random numbers and uses the best quality random seeding sources of the system.choice(sequence)
method also works just like therandom.choice()
method.randbelow(n)
function returns a random integer in the range[0, n)
.randbits(k)
method returns an integer withk
random bits.token_bytes([nbytes=None])
function returns a random byte string. Ifnbytes
is not provided, a reasonable default is used; if provided, the returned string contains that many bytes.token_hex([nbytes=None])
function returns a random text string in hex. The bytes used in the string are converted to two hex digits each.token_urlsafe([nbytes=None])
function returns a random, URL-safe text string of random bytes...