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

1""" 

2======================== 

3Random Number Generation 

4======================== 

5 

6Use ``default_rng()`` to create a `Generator` and call its methods. 

7 

8=============== ========================================================= 

9Generator 

10--------------- --------------------------------------------------------- 

11Generator Class implementing all of the random number distributions 

12default_rng Default constructor for ``Generator`` 

13=============== ========================================================= 

14 

15============================================= === 

16BitGenerator Streams that work with Generator 

17--------------------------------------------- --- 

18MT19937 

19PCG64 

20Philox 

21SFC64 

22============================================= === 

23 

24============================================= === 

25Getting entropy to initialize a BitGenerator 

26--------------------------------------------- --- 

27SeedSequence 

28============================================= === 

29 

30 

31Legacy 

32------ 

33 

34For backwards compatibility with previous versions of numpy before 1.17, the 

35various aliases to the global `RandomState` methods are left alone and do not 

36use the new `Generator` API. 

37 

38==================== ========================================================= 

39Utility functions 

40-------------------- --------------------------------------------------------- 

41random Uniformly distributed floats over ``[0, 1)`` 

42bytes Uniformly distributed random bytes. 

43permutation Randomly permute a sequence / generate a random sequence. 

44shuffle Randomly permute a sequence in place. 

45choice Random sample from 1-D array. 

46==================== ========================================================= 

47 

48==================== ========================================================= 

49Compatibility 

50functions - removed 

51in the new API 

52-------------------- --------------------------------------------------------- 

53rand Uniformly distributed values. 

54randn Normally distributed values. 

55ranf Uniformly distributed floating point numbers. 

56random_integers Uniformly distributed integers in a given range. 

57 (deprecated, use ``integers(..., closed=True)`` instead) 

58random_sample Alias for `random_sample` 

59randint Uniformly distributed integers in a given range 

60seed Seed the legacy random number generator. 

61==================== ========================================================= 

62 

63==================== ========================================================= 

64Univariate 

65distributions 

66-------------------- --------------------------------------------------------- 

67beta Beta distribution over ``[0, 1]``. 

68binomial Binomial distribution. 

69chisquare :math:`\\chi^2` distribution. 

70exponential Exponential distribution. 

71f F (Fisher-Snedecor) distribution. 

72gamma Gamma distribution. 

73geometric Geometric distribution. 

74gumbel Gumbel distribution. 

75hypergeometric Hypergeometric distribution. 

76laplace Laplace distribution. 

77logistic Logistic distribution. 

78lognormal Log-normal distribution. 

79logseries Logarithmic series distribution. 

80negative_binomial Negative binomial distribution. 

81noncentral_chisquare Non-central chi-square distribution. 

82noncentral_f Non-central F distribution. 

83normal Normal / Gaussian distribution. 

84pareto Pareto distribution. 

85poisson Poisson distribution. 

86power Power distribution. 

87rayleigh Rayleigh distribution. 

88triangular Triangular distribution. 

89uniform Uniform distribution. 

90vonmises Von Mises circular distribution. 

91wald Wald (inverse Gaussian) distribution. 

92weibull Weibull distribution. 

93zipf Zipf's distribution over ranked data. 

94==================== ========================================================= 

95 

96==================== ========================================================== 

97Multivariate 

98distributions 

99-------------------- ---------------------------------------------------------- 

100dirichlet Multivariate generalization of Beta distribution. 

101multinomial Multivariate generalization of the binomial distribution. 

102multivariate_normal Multivariate generalization of the normal distribution. 

103==================== ========================================================== 

104 

105==================== ========================================================= 

106Standard 

107distributions 

108-------------------- --------------------------------------------------------- 

109standard_cauchy Standard Cauchy-Lorentz distribution. 

110standard_exponential Standard exponential distribution. 

111standard_gamma Standard Gamma distribution. 

112standard_normal Standard normal distribution. 

113standard_t Standard Student's t-distribution. 

114==================== ========================================================= 

115 

116==================== ========================================================= 

117Internal functions 

118-------------------- --------------------------------------------------------- 

119get_state Get tuple representing internal state of generator. 

120set_state Set state of generator. 

121==================== ========================================================= 

122 

123 

124""" 

125__all__ = [ 

126 'beta', 

127 'binomial', 

128 'bytes', 

129 'chisquare', 

130 'choice', 

131 'dirichlet', 

132 'exponential', 

133 'f', 

134 'gamma', 

135 'geometric', 

136 'get_state', 

137 'gumbel', 

138 'hypergeometric', 

139 'laplace', 

140 'logistic', 

141 'lognormal', 

142 'logseries', 

143 'multinomial', 

144 'multivariate_normal', 

145 'negative_binomial', 

146 'noncentral_chisquare', 

147 'noncentral_f', 

148 'normal', 

149 'pareto', 

150 'permutation', 

151 'poisson', 

152 'power', 

153 'rand', 

154 'randint', 

155 'randn', 

156 'random', 

157 'random_integers', 

158 'random_sample', 

159 'ranf', 

160 'rayleigh', 

161 'sample', 

162 'seed', 

163 'set_state', 

164 'shuffle', 

165 'standard_cauchy', 

166 'standard_exponential', 

167 'standard_gamma', 

168 'standard_normal', 

169 'standard_t', 

170 'triangular', 

171 'uniform', 

172 'vonmises', 

173 'wald', 

174 'weibull', 

175 'zipf', 

176] 

177 

178# add these for module-freeze analysis (like PyInstaller) 

179from . import _pickle 

180from . import _common 

181from . import _bounded_integers 

182 

183from ._generator import Generator, default_rng 

184from .bit_generator import SeedSequence, BitGenerator 

185from ._mt19937 import MT19937 

186from ._pcg64 import PCG64 

187from ._philox import Philox 

188from ._sfc64 import SFC64 

189from .mtrand import * 

190 

191__all__ += ['Generator', 'RandomState', 'SeedSequence', 'MT19937', 

192 'Philox', 'PCG64', 'SFC64', 'default_rng', 'BitGenerator'] 

193 

194 

195def __RandomState_ctor(): 

196 """Return a RandomState instance. 

197 

198 This function exists solely to assist (un)pickling. 

199 

200 Note that the state of the RandomState returned here is irrelevant, as this 

201 function's entire purpose is to return a newly allocated RandomState whose 

202 state pickle can set. Consequently the RandomState returned by this function 

203 is a freshly allocated copy with a seed=0. 

204 

205 See https://github.com/numpy/numpy/issues/4763 for a detailed discussion 

206 

207 """ 

208 return RandomState(seed=0) 

209 

210 

211from numpy._pytesttester import PytestTester 

212test = PytestTester(__name__) 

213del PytestTester