How to use the randomgen.legacy._legacy._LegacyGenerator function in randomgen

To help you get started, we’ve selected a few randomgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bashtage / randomgen / randomgen / legacy / legacy.py View on Github external
from randomgen.generator import RandomGenerator
from randomgen.mt19937 import MT19937
from randomgen.legacy._legacy import _LegacyGenerator
import randomgen.pickle

# Attributes in RandomGenerator that should not appear in LegacyGenerator
_HIDDEN_ATTRIBUTES = ['complex_normal']

_LEGACY_ATTRIBUTES = tuple(a for a in dir(
    _LegacyGenerator) if not a.startswith('_'))

_LEGACY_ATTRIBUTES += ('__getstate__', '__setstate__', '__reduce__')


def with_metaclass(meta, *bases):
    """Create a base class with a metaclass."""
    # This requires a bit of explanation: the basic idea is to make a dummy
    # metaclass for one level of class instantiation that replaces itself with
    # the actual metaclass.

    # From six, https://raw.githubusercontent.com/benjaminp/six
    class metaclass(type):

        def __new__(cls, name, this_bases, d):
            return meta(name, bases, d)
github bashtage / randomgen / randomgen / legacy / legacy.py View on Github external
def __init__(self, brng=None):
        if brng is None:
            brng = MT19937()
        super(LegacyGenerator, self).__init__(brng)
        self.__legacy = _LegacyGenerator(brng)
github bashtage / randomgen / randomgen / legacy / legacy.py View on Github external
>>> lg.standard_exponential()
    1.6465621229906502

    The equivalent commands from NumPy produce identical output.

    >>> from numpy.random import RandomState
    >>> rs = RandomState(12345)
    >>> x = rs.standard_normal(10)
    >>> rs.shuffle(x)
    >>> x[0]
    0.09290787674371767
    >>> rs.standard_exponential()
    1.6465621229906502
    """

    __atttributes = sorted(set(dir(_LegacyGenerator) +
                               dir(RandomGenerator))
                           .difference(_HIDDEN_ATTRIBUTES))

    def __init__(self, brng=None):
        if brng is None:
            brng = MT19937()
        super(LegacyGenerator, self).__init__(brng)
        self.__legacy = _LegacyGenerator(brng)

    def __getattribute__(self, name):
        if name in _HIDDEN_ATTRIBUTES:
            raise AttributeError('No attribute {0}'.format(name))
        if name in _LEGACY_ATTRIBUTES:
            return self.__legacy.__getattribute__(name)
        return object.__getattribute__(self, name)