Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 3
    Nice use of generator expressions. But while we're saving memory, might as well use xrange instead of range.
    – Zach B
    Commented Dec 24, 2009 at 8:10
  • 4
    CytokineStorm, as of Python 3.x, range() behaves the same as xrange(). Commented Dec 24, 2009 at 9:28
  • Just keep in mind that any sequence generated by the random module is not cryptographically secure.
    – Federico
    Commented Jun 23, 2013 at 21:14
  • @Federico: Unless you use random.SystemRandom(), which should be as cryptographically secure as the OS supports. In modules that need cryptographic randomness, I often do: import random, random = random.SystemRandom() to replace the module with an instance of the class that provides OS crypto-randomness. SystemRandom is the random.Random API, with randomness provided by os.urandom instead of Mersenne Twister (os.urandom is backed by stuff like Window's CryptGenRandom, UNIX-like /dev/urandom, etc.). Commented Oct 17, 2016 at 14:29