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

Function random_state_data

dask/utils.py:541–562  ·  view source on GitHub ↗

Return a list of arrays that can initialize ``np.random.RandomState``. Parameters ---------- n : int Number of arrays to return. random_state : int or np.random.RandomState, optional If an int, is used to seed a new ``RandomState``.

(n: int, random_state=None)

Source from the content-addressed store, hash-verified

539
540
541def random_state_data(n: int, random_state=None) -> list:
542 """Return a list of arrays that can initialize
543 ``np.random.RandomState``.
544
545 Parameters
546 ----------
547 n : int
548 Number of arrays to return.
549 random_state : int or np.random.RandomState, optional
550 If an int, is used to seed a new ``RandomState``.
551 """
552 import numpy as np
553
554 if not all(
555 hasattr(random_state, attr) for attr in ["normal", "beta", "bytes", "uniform"]
556 ):
557 random_state = np.random.RandomState(random_state)
558
559 random_data = random_state.bytes(624 * n * 4) # `n * 624` 32-bit integers
560 l = list(np.frombuffer(random_data, dtype="<u4").reshape((n, -1)))
561 assert len(l) == n
562 return l
563
564
565def is_integer(i) -> bool:

Callers 9

random_state_dataMethod · 0.90
sampleMethod · 0.90
_layerMethod · 0.90
with_specFunction · 0.90
test_random_state_dataFunction · 0.90
choiceMethod · 0.90
_wrap_funcFunction · 0.90
_infoMethod · 0.90
state_dataMethod · 0.90

Calls 3

allFunction · 0.85
reshapeMethod · 0.80
RandomStateMethod · 0.45

Tested by 1

test_random_state_dataFunction · 0.72