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