In the docs (python 3.5) for initializing a random number from a seed:
Initialize the random number generator.
If a is omitted or None, the current system time is used. If
randomness sources are provided by the operating system, they are used
instead of the system time (see the os.urandom() function for details
If a is an int, it is used directly.
With version 2 (the default), a str, bytes, or bytearray object gets
converted to an int and all of its bits are used. With version 1, the
hash() of a is used instead.
x = 1
type(x) # <class 'int'>
y = 123456789123456789123456789123456789123456789123456789123456789123456789
type(y) # <class 'int'>
z = x+y
z-y # 1 (no rounding error for a 71 digit number)
What's great about open source is the ability to simply view the code with a question. This is the source of
if a is None: try: # Seed with enough bytes to span the 19937 bit # state space for the Mersenne Twister a = int.from_bytes(_urandom(2500), 'big') except NotImplementedError: import time a = int(time.time() * 256) # use fractional seconds if version == 2: if isinstance(a, (str, bytes, bytearray)): if isinstance(a, str): a = a.encode() a += _sha512(a).digest() a = int.from_bytes(a, 'big') super().seed(a) self.gauss_next = None
You can see that if
version == 2 and
bytes are provided, it takes the SHA512 of
a, appends it, and uses
int.from_bytes, generating a very large int and guaranteeing at least a 512-bit seed, even with very small custom inputs.
As noted below, the end result is that the seed is guaranteed to have a length of at least 624 bits.