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