def init_rng(seed, *keys, propagate=True): """ Initialize the random infrastructure with a seed. This function should generally be called very early in the setup. .. warning:: This method is deprecated. Use :func:`seedbank.initialize` instead. Args: seed(int or numpy.random.SeedSequence): The random seed to initialize with. keys: Additional keys, to use as a ``spawn_key`` on NumPy 1.17. Passed to :func:`derive_seed`. propagate(bool): If ``True``, initialize other RNG infrastructure. This currently initializes: * :func:`np.random.seed` * :func:`random.seed` If ``propagate=False``, LensKit is still fully seeded — no component included with LensKit uses any of the global RNGs, they all use RNGs seeded with the specified seed. Returns: The random seed. """ warnings.warn('init_rng is deprecated, use seedbank.initialize', DeprecationWarning) seedbank.initialize(seed, *keys)
def test_numba_init(): initialize(42) a1 = _numba_rand() # if we re-initialize, should get the same result! initialize(42) a2 = _numba_rand() assert a1 == a2
def test_derive_seed(): initialize(42) s2 = derive_seed() assert s2.entropy == 42 assert s2.spawn_key == (0,)
def test_derive_seed_str(): initialize(42) s2 = derive_seed(b'wombat') assert s2.entropy == 42 assert all(s2.spawn_key[0] == make_key(b'wombat'))
def test_derive_seed_intkey(): initialize(42) s2 = derive_seed(10, 7) assert s2.entropy == 42 assert s2.spawn_key == (10, 7)
def test_int_seed_new(): initialize(42) seed = int_seed(seed=derive_seed()) assert seed != int_seed()
def test_initialize(): initialize(42) assert _root_state.seed.entropy == 42 assert len(_root_state.seed.spawn_key) == 0 assert root_seed().entropy == 42
def test_int_seed_words(): initialize(42) words = int_seed(5) assert all(words == root_seed().generate_state(5))
def test_int_seed(): initialize(42) assert int_seed() == _root_state.int_seed
def test_initialize_key(): initialize(42, 'wombat') assert _root_state.seed.entropy == 42 k = make_key('wombat') assert all(_root_state.seed.spawn_key[0] == k) assert root_seed().entropy == 42