summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2019-04-10 20:18:02 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-04-10 20:18:02 (GMT)
commitd914596a671c4b0f13641359cf43aa0d6fc05070 (patch)
tree7f31160b10be89841a962387d84b23e39a5f0881 /Lib/random.py
parent6955d44b41058e3bcc59ff41860bd4cc8948c441 (diff)
downloadcpython-d914596a671c4b0f13641359cf43aa0d6fc05070.zip
cpython-d914596a671c4b0f13641359cf43aa0d6fc05070.tar.gz
cpython-d914596a671c4b0f13641359cf43aa0d6fc05070.tar.bz2
bpo-36559: random module: optimize sha512 import (GH-12742)
The random module now prefers the lean internal _sha512 module over hashlib for seed(version=2) to optimize import time. Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 79ef30d..53981f3 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -42,11 +42,18 @@ from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
from _collections_abc import Set as _Set, Sequence as _Sequence
-from hashlib import sha512 as _sha512
from itertools import accumulate as _accumulate, repeat as _repeat
from bisect import bisect as _bisect
import os as _os
+try:
+ # hashlib is pretty heavy to load, try lean internal module first
+ from _sha512 import sha512 as _sha512
+except ImportError:
+ # fallback to official implementation
+ from hashlib import sha512 as _sha512
+
+
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
"randrange","shuffle","normalvariate","lognormvariate",
"expovariate","vonmisesvariate","gammavariate","triangular",