random.SystemRandom().randint() inefficient

Weatherby,Gerard gweatherby at uchc.edu
Tue Jul 26 13:30:32 EDT 2022


Absolutely. The task (“generate a random number”) is ill-defined.

Want a fast random number? Use 552015933 (I just retrieved it from random.org).

Want a true random number, use random.org API. (https://api.random.org/pricing).

Something in between, follow approaches Stefan suggests.



—
Gerard Weatherby | Application Architect NMRbox | NAN | Department of Molecular Biology and Biophysics
 UConn Health 263 Farmington Avenue, Farmington, CT 06030-6406 uchc.edu
On Jul 26, 2022, 11:45 AM -0400, Stefan Ram <ram at zedat.fu-berlin.de>, wrote:
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

Cecil Westerhof <Cecil at decebal.nl> writes:
I need to get a random integer.

There are all kinds of trade-offs. When you need entropy,
the function sometimes has to collect data from hardware,
which takes some time. Pseudo-random integers sometimes can
be calculated faster. As a compromise, you can get some
entropy and use it to initialize ("seed") a pseudo-random
number generator and then get some pseudo-random numbers
until you seed it again. A linear-congruential generator
should be fast enough, but in some cases might not be random
enough.


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kjJ7U6kkSW8uOTWJCnHeXn0Acczd619asmIrVMA_NOqvP_JMqqQ1Rpp61sptQucbOuEFGb6ot499_FqaRajiS9s$


More information about the Python-list mailing list