megengine.random.RNG

class RNG(seed=None, device=None)[源代码]

RNG exposes a number of methods for generating random numbers.

参数
  • seed (Optional[int]) – random seed used to initialize the pseudo-random number generator. Default: None

  • device (Optional[str]) – the device of generated tensor. Default: None

实际案例

import megengine.random as rand
rng = rand.RNG(seed=100)
x = rng.uniform(size=(2, 2))
print(x.numpy())

Outputs:

[[0.84811664 0.6147553 ]
 [0.59429836 0.64727545]]

方法

beta(alpha, beta[, size])

Random variable with Beta distribution \(\operatorname{Beta}(\alpha, \beta)\).

gamma(shape[, scale, size])

Random variable with Gamma distribution \(\Gamma(k, \theta)\).

normal([mean, std, size])

Random variable with Gaussian distribution \(N(\mu, \sigma)\).

permutation(n, *[, dtype])

Generates a random permutation of integers from \(0\) to \(n - 1\).

poisson(lam[, size])

Random variable with poisson distribution \(\operatorname{Poisson}(\lambda)\).

uniform([low, high, size])

Random variable with uniform distribution $U(0, 1)$.