Beispiel #1
0
def rng(spec=None, *, legacy=False):
    """
    Get a random number generator.  This is similar to :func:`sklearn.utils.check_random_seed`, but
    it usually returns a :class:`numpy.random.Generator` instead.

    .. warning::

        This method is deprecated. Use :func:`seedbank.numpy_rng` instead.


    Args:
        spec:
            The spec for this RNG.  Can be any of the following types:

            * ``int``
            * ``None``
            * :class:`numpy.random.SeedSequence`
            * :class:`numpy.random.mtrand.RandomState`
            * :class:`numpy.random.Generator`
        legacy(bool):
            If ``True``, return :class:`numpy.random.mtrand.RandomState` instead of a new-style
            :class:`numpy.random.Generator`.

    Returns:
        numpy.random.Generator: A random number generator.
    """
    warnings.warn('rng is deprecated, use seedbank.numpy_rng',
                  DeprecationWarning)

    if legacy:
        return seedbank.numpy_random_state(spec)
    else:
        return seedbank.numpy_rng(spec)
Beispiel #2
0
def test_random_state_seed():
    rng = numpy_random_state(42, )
    assert isinstance(rng, np.random.RandomState)
Beispiel #3
0
def test_random_state_ss():
    seq = np.random.SeedSequence(42)
    rng = numpy_random_state(seq)
    assert isinstance(rng, np.random.RandomState)
Beispiel #4
0
def test_generator_convert_to_rs():
    rng1 = np.random.default_rng()
    rng = numpy_random_state(rng1)
    assert isinstance(rng, np.random.RandomState)
Beispiel #5
0
def test_random_state_passthrough():
    rng1 = np.random.RandomState()
    rng = numpy_random_state(rng1)
    assert isinstance(rng, np.random.RandomState)