This module gives direct access to Windows Cryptographic API CryptGetRandom() function, which is cryptographically strong pseudo-random number generator (PRNG) on Windows:
-
long() returns random unsigned long integer
>>> import winrandom >>> winrandom.long() 2141228967
-
bytes(n) returns n random bytes
>>> winrandom.bytes(10) "\x1e'^';]\xda\xf0\x91\xba"
-
range(max) returns a random integer i from range 0 to max (0 <= i < max). Random data originates from the PRNG but to ensure that the integer is not biased an algorithm from NIST SP800-90 is used (B.5.1.1 Simple Discard Method). In addition, in the internal loop a continuous random number generator test is executed (FIPS 140-2 p. 44).
>>> winrandom.range(1000) 706
- 1.0 added winrandom.long()
- 1.1 added winrandom.bytes(num)
- 1.2 added winrandom.range(max)