MCPcopy Create free account
hub / github.com/dask/dask / RandomState

Class RandomState

dask/array/_array_expr/random.py:473–752  ·  view source on GitHub ↗

Mersenne Twister pseudo-random number generator This object contains state to deterministically generate pseudo-random numbers from a variety of probability distributions. It is identical to ``np.random.RandomState`` except that all functions also take a ``chunks=`` keyword ar

Source from the content-addressed store, hash-verified

471
472
473class RandomState:
474 """
475 Mersenne Twister pseudo-random number generator
476
477 This object contains state to deterministically generate pseudo-random
478 numbers from a variety of probability distributions. It is identical to
479 ``np.random.RandomState`` except that all functions also take a ``chunks=``
480 keyword argument.
481
482 Parameters
483 ----------
484 seed: Number
485 Object to pass to RandomState to serve as deterministic seed
486 RandomState: Callable[seed] -> RandomState
487 A callable that, when provided with a ``seed`` keyword provides an
488 object that operates identically to ``np.random.RandomState`` (the
489 default). This might also be a function that returns a
490 ``mkl_random``, or ``cupy.random.RandomState`` object.
491
492 Examples
493 --------
494 >>> import dask.array as da
495 >>> state = da.random.RandomState(1234) # a seed
496 >>> x = state.normal(10, 0.1, size=3, chunks=(2,))
497 >>> x.compute()
498 array([10.01867852, 10.04812289, 9.89649746])
499
500 See Also
501 --------
502 np.random.RandomState
503 """
504
505 def __init__(self, seed=None, RandomState=None):
506 self._numpy_state = np.random.RandomState(seed)
507 self._RandomState = (
508 array_creation_dispatch.RandomState if RandomState is None else RandomState
509 )
510
511 @property
512 def _backend(self):
513 # Assumes typename(self._RandomState) starts with
514 # an importable array-library name (e.g. "numpy" or "cupy")
515 _backend_name = typename(self._RandomState).split(".")[0]
516 return importlib.import_module(_backend_name)
517
518 def seed(self, seed=None):
519 self._numpy_state.seed(seed)
520
521 @derived_from(np.random.RandomState, skipblocks=1)
522 def beta(self, a, b, size=None, chunks="auto", **kwargs):
523 return _wrap_func(self, "beta", a, b, size=size, chunks=chunks, **kwargs)
524
525 @derived_from(np.random.RandomState, skipblocks=1)
526 def binomial(self, n, p, size=None, chunks="auto", **kwargs):
527 return _wrap_func(self, "binomial", n, p, size=size, chunks=chunks, **kwargs)
528
529 @derived_from(np.random.RandomState, skipblocks=1)
530 def chisquare(self, df, size=None, chunks="auto", **kwargs):

Callers 2

_apply_randomFunction · 0.70
wrapperFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected