What is the difference between random.SystemRandom().choice()
& random.choice()
in python?
I have seen the former being used, in more than one place. But its not mention py2 or py3 documentation.
random.SystemRandom
is a random number generator class intended for cryptographic use. It uses os.urandom
for its underlying byte stream; os.urandom
pulls from an OS-dependent cryptographic random number source, sometimes /dev/urandom
(but not always, even when /dev/urandom
exists.
The SystemRandom
class provides all random number generation methods the random
module itself does, with the same meanings, just using a cryptographic RNG to implement them. random.choice
and the choice
method of a SystemRandom
instance both make a random choice from an input sequence, but only SystemRandom
is suitable for cryptographic use. random.choice
's choices can be predicted by an adversary without much difficulty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With