rand

Contents

rand#

class brainstate.random.rand(*dn, key=None, dtype=None)#

Random values in a given shape.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Parameters:
  • d0 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • ... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • dtype (str | type[Any] | dtype | SupportsDType) – Desired dtype of the result. Byteorder must be native. The default value is float.

  • key (int | Array | ndarray | None) – The key for the random number generator. If not given, the default random number generator is used.

Returns:

out – Random values.

Return type:

ndarray, shape (d0, d1, ..., dn)

See also

random

Examples

Generate random values in a 3x2 array:

>>> import brainstate
>>> arr = brainstate.random.rand(3, 2)
>>> print(arr.shape)  # (3, 2)
>>> print((arr >= 0).all() and (arr < 1).all())  # True