Score:1

Is Python's secrets module random enough for a raffle?

tr flag

Would secrets.choice be random enough to pick winners in a raffle?

Score:1
us flag

Yes it is. According to the Python documentation

The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.

In the background, secrets doesn't use a PRNG like random. In Linux specifically it uses \dev\urandom which is considered cryptographically secure and is used by popular cryptographic libraries like OpenSSL. In Windows, it uses RtlGenRandom.

tr flag
Thank you! So if I have a list of names `['John Smith', 'Jane Doe', 'Jane Doe', 'Joe Public']` (Jane Doe bought two tickets), and call `secrets.choice(names)` it will be as secure as drawing a random paper ticket?
benrg avatar
cn flag
`random` actually supports multiple generators including `SystemRandom` which uses the same urandom-or-equivalent source as `secrets` does. `secrets` was added later as a module that would be harder to accidentally misuse if you need cryptographic randomness. @Someone, it's secure if you trust the computer you run it on. A paper drawing may (or may not) be more difficult to hack.
JAAAY avatar
us flag
@benrg Thanks, I didn't know that, I will update my answer accordingly
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.