Index: Python-3.5.0/Lib/random.py =================================================================== --- Python-3.5.0.orig/Lib/random.py +++ Python-3.5.0/Lib/random.py @@ -715,28 +715,29 @@ def _test(N=2000): # for most programs and is easier for the casual user than making them # instantiate their own Random() instance. -_inst = Random() -seed = _inst.seed -random = _inst.random -uniform = _inst.uniform -triangular = _inst.triangular -randint = _inst.randint -choice = _inst.choice -randrange = _inst.randrange -sample = _inst.sample -shuffle = _inst.shuffle -normalvariate = _inst.normalvariate -lognormvariate = _inst.lognormvariate -expovariate = _inst.expovariate -vonmisesvariate = _inst.vonmisesvariate -gammavariate = _inst.gammavariate -gauss = _inst.gauss -betavariate = _inst.betavariate -paretovariate = _inst.paretovariate -weibullvariate = _inst.weibullvariate -getstate = _inst.getstate -setstate = _inst.setstate -getrandbits = _inst.getrandbits +_inst = None + +_NAMES = """\ +seed random uniform triangular randint choice randrange sample \ +shuffle normalvariate lognormalvariate expovariate gammavariate \ +gauss betavariate paretovariate weibullvariate getstate setstate \ +getrandbits\ +""".split() + +def _wait_until_called(name): + def _call_name(*args, **kwargs): + global _inst + if not _inst: + _inst = Random() + for fname in _NAMES: + globals()[fname] = getattr(_inst, fname) + + return globals()[name](*args, **kwargs) + + return _call_name + +for name in _NAMES: + globals()[name] = _wait_until_called(name) if __name__ == '__main__': _test()