Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from .mtrand import RandomState 

2from ._philox import Philox 

3from ._pcg64 import PCG64 

4from ._sfc64 import SFC64 

5 

6from ._generator import Generator 

7from ._mt19937 import MT19937 

8 

9BitGenerators = {'MT19937': MT19937, 

10 'PCG64': PCG64, 

11 'Philox': Philox, 

12 'SFC64': SFC64, 

13 } 

14 

15 

16def __generator_ctor(bit_generator_name='MT19937'): 

17 """ 

18 Pickling helper function that returns a Generator object 

19 

20 Parameters 

21 ---------- 

22 bit_generator_name: str 

23 String containing the core BitGenerator 

24 

25 Returns 

26 ------- 

27 rg: Generator 

28 Generator using the named core BitGenerator 

29 """ 

30 if bit_generator_name in BitGenerators: 

31 bit_generator = BitGenerators[bit_generator_name] 

32 else: 

33 raise ValueError(str(bit_generator_name) + ' is not a known ' 

34 'BitGenerator module.') 

35 

36 return Generator(bit_generator()) 

37 

38 

39def __bit_generator_ctor(bit_generator_name='MT19937'): 

40 """ 

41 Pickling helper function that returns a bit generator object 

42 

43 Parameters 

44 ---------- 

45 bit_generator_name: str 

46 String containing the name of the BitGenerator 

47 

48 Returns 

49 ------- 

50 bit_generator: BitGenerator 

51 BitGenerator instance 

52 """ 

53 if bit_generator_name in BitGenerators: 

54 bit_generator = BitGenerators[bit_generator_name] 

55 else: 

56 raise ValueError(str(bit_generator_name) + ' is not a known ' 

57 'BitGenerator module.') 

58 

59 return bit_generator() 

60 

61 

62def __randomstate_ctor(bit_generator_name='MT19937'): 

63 """ 

64 Pickling helper function that returns a legacy RandomState-like object 

65 

66 Parameters 

67 ---------- 

68 bit_generator_name: str 

69 String containing the core BitGenerator 

70 

71 Returns 

72 ------- 

73 rs: RandomState 

74 Legacy RandomState using the named core BitGenerator 

75 """ 

76 if bit_generator_name in BitGenerators: 

77 bit_generator = BitGenerators[bit_generator_name] 

78 else: 

79 raise ValueError(str(bit_generator_name) + ' is not a known ' 

80 'BitGenerator module.') 

81 

82 return RandomState(bit_generator())