# Path: surprise/utils.py
# def get_rng(random_state):
#     """Return a 'validated' RNG.
# 
#     If random_state is None, use RandomState singleton from numpy.  Else if
#     it's an integer, consider it's a seed and initialized an rng with that
#     seed. If it's already an rng, return it.
#     """
#     if random_state is None:
#         return np.random.mtrand._rand
#     elif isinstance(random_state, (numbers.Integral, np.integer)):
#         return np.random.RandomState(random_state)
#     if isinstance(random_state, np.random.RandomState):
#         return random_state
#     raise ValueError('Wrong random state. Expecting None, an int or a numpy '
#                      'RandomState instance, got a '
#                      '{}'.format(type(random_state)))


import numpy as np
import pytest
from surprise.utils import get_rng
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)




def test_get_rng():

    # assert two RNG with same int are the same
    rng_a = get_rng(12)
    rng_b = get_rng(12)
    a = [rng_a.rand() for _ in range(10)]
    b = [rng_b.rand() for _ in range(10)]
    assert a == b

    # assert passing an int returns the corresponding numpy rng instance
    rng_a = get_rng(12)
    rng_b = np.random.RandomState(12)

    a = [rng_a.rand() for _ in range(10)]
    b = [rng_b.rand() for _ in range(10)]
    assert a == b

    # Make sure this is ok
    get_rng(None)

    with pytest.raises(ValueError):

# Path: surprise/utils.py
# def get_rng(random_state):
#     """Return a 'validated' RNG.
# 
#     If random_state is None, use RandomState singleton from numpy.  Else if
#     it's an integer, consider it's a seed and initialized an rng with that
#     seed. If it's already an rng, return it.
#     """
#     if random_state is None:
#         return np.random.mtrand._rand
#     elif isinstance(random_state, (numbers.Integral, np.integer)):
#         return np.random.RandomState(random_state)
#     if isinstance(random_state, np.random.RandomState):
#         return random_state
#     raise ValueError('Wrong random state. Expecting None, an int or a numpy '
#                      'RandomState instance, got a '
#                      '{}'.format(type(random_state)))


# Path: tests/test_utils.py
import numpy as np
import pytest
from surprise.utils import get_rng

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)




def test_get_rng():

    # assert two RNG with same int are the same
    rng_a = get_rng(12)
    rng_b = get_rng(12)
    a = [rng_a.rand() for _ in range(10)]
    b = [rng_b.rand() for _ in range(10)]
    assert a == b

    # assert passing an int returns the corresponding numpy rng instance
    rng_a = get_rng(12)
    rng_b = np.random.RandomState(12)

    a = [rng_a.rand() for _ in range(10)]
    b = [rng_b.rand() for _ in range(10)]
    assert a == b

    # Make sure this is ok
    get_rng(None)

    with pytest.raises(ValueError):

        get_rng(23.2)