summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2019-05-13 14:17:51 -0700
committermattip <matti.picus@gmail.com>2019-05-20 19:00:34 +0300
commit17e0070df93f4262908f884dca4b08cb7d0bba7f (patch)
tree2db0eec024d5e021a36e6dca9f4b97d118bc9444 /numpy
parentdd77ce3cb84986308986974acfe988575323f75a (diff)
downloadnumpy-17e0070df93f4262908f884dca4b08cb7d0bba7f.tar.gz
MAINT: Implement API changes for randomgen-derived code
remove numpy.random.gen, BRNG.generator, pcg*, rand, randn remove use_mask and Lemire's method, fix benchmarks for PCG removal convert brng to bitgen (in C) and bit_generator (in python) convert base R{NG,andom.*} to BitGenerator, fix last commit randint -> integers, remove rand, randn, random_integers RandomGenerator -> Generator, more "basic RNG" -> BitGenerator random_sample -> random, jump -> jumped, resync with randomgen Remove derived code from entropy Port over changes accepted in upstream to protect log(0.0) where relevant fix doctests for jumped, better document choice Remove Python 2.7 shims Use NPY_INLINE to simplify Fix performance.py to work Renam directory brng to bit_generators Fix examples wiht new directory structure Clarify relationship to historical RandomState Remove references to .generator Rename xoshiro256/512starstar
Diffstat (limited to 'numpy')
-rw-r--r--numpy/random/LICENSE.md45
-rw-r--r--numpy/random/__init__.py76
-rw-r--r--numpy/random/_pickle.py91
-rw-r--r--numpy/random/bounded_integers.pxd.in4
-rw-r--r--numpy/random/bounded_integers.pyx.in12
-rw-r--r--numpy/random/common.pxd32
-rw-r--r--numpy/random/common.pyx79
-rw-r--r--numpy/random/distributions.pxd144
-rw-r--r--numpy/random/dsfmt.pyx192
-rw-r--r--numpy/random/entropy.pyx9
-rw-r--r--numpy/random/examples/cython/extending.pyx20
-rw-r--r--numpy/random/examples/cython/extending_distributions.pyx22
-rw-r--r--numpy/random/examples/cython/setup.py10
-rw-r--r--numpy/random/examples/numba/extending_distributions.py14
-rw-r--r--numpy/random/generator.pyx723
-rw-r--r--numpy/random/legacy_distributions.pxd56
-rw-r--r--numpy/random/mt19937.pyx175
-rw-r--r--numpy/random/mtrand.pyx289
-rw-r--r--numpy/random/pcg32.pyx387
-rw-r--r--numpy/random/pcg64.pyx426
-rw-r--r--numpy/random/philox.pyx212
-rw-r--r--numpy/random/setup.py25
-rw-r--r--numpy/random/src/common/LICENSE.md29
-rw-r--r--numpy/random/src/common/inttypes.h306
-rw-r--r--numpy/random/src/common/stdint.h258
-rw-r--r--numpy/random/src/distributions/distributions.c709
-rw-r--r--numpy/random/src/distributions/distributions.h170
-rw-r--r--numpy/random/src/entropy/LICENSE.md25
-rw-r--r--numpy/random/src/entropy/entropy.c70
-rw-r--r--numpy/random/src/entropy/entropy.h34
-rw-r--r--numpy/random/src/legacy/LICENSE.md30
-rw-r--r--numpy/random/src/legacy/distributions-boxmuller.c46
-rw-r--r--numpy/random/src/legacy/distributions-boxmuller.h48
-rw-r--r--numpy/random/src/mt19937/mt19937.h8
-rw-r--r--numpy/random/src/pcg32/LICENSE.md22
-rw-r--r--numpy/random/src/pcg32/pcg-advance-64.c62
-rw-r--r--numpy/random/src/pcg32/pcg32-test-data-gen.c59
-rw-r--r--numpy/random/src/pcg32/pcg32.c30
-rw-r--r--numpy/random/src/pcg32/pcg32.h89
-rw-r--r--numpy/random/src/pcg32/pcg_variants.h2210
-rw-r--r--numpy/random/src/pcg64/LICENSE.md22
-rw-r--r--numpy/random/src/pcg64/pcg64-benchmark.c42
-rw-r--r--numpy/random/src/pcg64/pcg64-test-data-gen.c73
-rw-r--r--numpy/random/src/pcg64/pcg64.c162
-rw-r--r--numpy/random/src/pcg64/pcg64.h246
-rw-r--r--numpy/random/src/pcg64/pcg64.orig.c11
-rw-r--r--numpy/random/src/pcg64/pcg64.orig.h2025
-rw-r--r--numpy/random/src/philox/philox.c4
-rw-r--r--numpy/random/src/philox/philox.h35
-rw-r--r--numpy/random/src/splitmix64/splitmix64.h9
-rw-r--r--numpy/random/src/threefry/threefry.c4
-rw-r--r--numpy/random/src/threefry/threefry.h26
-rw-r--r--numpy/random/src/threefry32/threefry32.c4
-rw-r--r--numpy/random/src/threefry32/threefry32.h34
-rw-r--r--numpy/random/src/xoroshiro128/xoroshiro128.c4
-rw-r--r--numpy/random/src/xoroshiro128/xoroshiro128.h20
-rw-r--r--numpy/random/src/xorshift1024/xorshift1024.c6
-rw-r--r--numpy/random/src/xorshift1024/xorshift1024.h18
-rw-r--r--numpy/random/src/xoshiro256/LICENSE.md (renamed from numpy/random/src/xoshiro256starstar/LICENSE.md)0
-rw-r--r--numpy/random/src/xoshiro256/xoshiro256-test-data-gen.c (renamed from numpy/random/src/xoshiro256starstar/xoshiro256starstar-test-data-gen.c)16
-rw-r--r--numpy/random/src/xoshiro256/xoshiro256.c (renamed from numpy/random/src/xoshiro256starstar/xoshiro256starstar.c)11
-rw-r--r--numpy/random/src/xoshiro256/xoshiro256.h53
-rw-r--r--numpy/random/src/xoshiro256/xoshiro256.orig.c (renamed from numpy/random/src/xoshiro256starstar/xoshiro256starstar.orig.c)0
-rw-r--r--numpy/random/src/xoshiro256/xoshiro256.orig.h (renamed from numpy/random/src/xoshiro256starstar/xoshiro256starstar.orig.h)0
-rw-r--r--numpy/random/src/xoshiro256starstar/xoshiro256starstar.h63
-rw-r--r--numpy/random/src/xoshiro512/LICENSE.md (renamed from numpy/random/src/xoshiro512starstar/LICENSE.md)0
-rw-r--r--numpy/random/src/xoshiro512/xoshiro512-test-data-gen.c (renamed from numpy/random/src/xoshiro512starstar/xoshiro512starstar-test-data-gen.c)16
-rw-r--r--numpy/random/src/xoshiro512/xoshiro512.c (renamed from numpy/random/src/xoshiro512starstar/xoshiro512starstar.c)13
-rw-r--r--numpy/random/src/xoshiro512/xoshiro512.h (renamed from numpy/random/src/xoshiro512starstar/xoshiro512starstar.h)35
-rw-r--r--numpy/random/src/xoshiro512/xoshiro512.orig.c (renamed from numpy/random/src/xoshiro512starstar/xoshiro512starstar.orig.c)2
-rw-r--r--numpy/random/src/xoshiro512/xoshiro512.orig.h (renamed from numpy/random/src/xoshiro512starstar/xoshiro512starstar.orig.h)0
-rw-r--r--numpy/random/tests/data/pcg32-testset-1.csv1001
-rw-r--r--numpy/random/tests/data/pcg32-testset-2.csv1001
-rw-r--r--numpy/random/tests/data/pcg64-testset-1.csv1001
-rw-r--r--numpy/random/tests/data/pcg64-testset-2.csv1001
-rw-r--r--numpy/random/tests/data/xoshiro256-testset-1.csv (renamed from numpy/random/tests/data/xoshiro256starstar-testset-1.csv)0
-rw-r--r--numpy/random/tests/data/xoshiro256-testset-2.csv (renamed from numpy/random/tests/data/xoshiro256starstar-testset-2.csv)0
-rw-r--r--numpy/random/tests/data/xoshiro512-testset-1.csv (renamed from numpy/random/tests/data/xoshiro512starstar-testset-1.csv)0
-rw-r--r--numpy/random/tests/data/xoshiro512-testset-2.csv (renamed from numpy/random/tests/data/xoshiro512starstar-testset-2.csv)0
-rw-r--r--numpy/random/tests/test_against_numpy.py74
-rw-r--r--numpy/random/tests/test_direct.py364
-rw-r--r--numpy/random/tests/test_generator_mt19937.py513
-rw-r--r--numpy/random/tests/test_generator_mt19937_regressions.py30
-rw-r--r--numpy/random/tests/test_random.py4
-rw-r--r--numpy/random/tests/test_randomstate.py10
-rw-r--r--numpy/random/tests/test_smoke.py459
-rw-r--r--numpy/random/threefry.pyx223
-rw-r--r--numpy/random/threefry32.pyx205
-rw-r--r--numpy/random/xoroshiro128.pyx221
-rw-r--r--numpy/random/xorshift1024.pyx216
-rw-r--r--numpy/random/xoshiro256.pyx (renamed from numpy/random/xoshiro256starstar.pyx)245
-rw-r--r--numpy/random/xoshiro512.pyx (renamed from numpy/random/xoshiro512starstar.pyx)238
92 files changed, 2862 insertions, 14146 deletions
diff --git a/numpy/random/LICENSE.md b/numpy/random/LICENSE.md
index caa665373..a6cf1b17e 100644
--- a/numpy/random/LICENSE.md
+++ b/numpy/random/LICENSE.md
@@ -64,45 +64,8 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.**
-# NumPy and Other Components
-
-Many parts of this module have been derived from NumPy. Other parts have been
-derived from original sources, often the algorithm's designer. The NumPy license
-is reproduced below. Component licenses are located with the component code.
-
-Copyright (c) 2005-2019, NumPy Developers.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the NumPy Developers nor the names of any
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-## Components
-
-Many of the components have their own license terms which are stored
-with the source for the component.
+# Components
+Many parts of this module have been derived from original sources,
+often the algorithm's designer. Component licenses are located with
+the component code.
diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py
index 431d97013..7c30ada15 100644
--- a/numpy/random/__init__.py
+++ b/numpy/random/__init__.py
@@ -3,37 +3,41 @@
Random Number Generation
========================
-Instantiate a RandomNumberGenerator (RNG) and wrap it in a RandomGenerator
-which will convert the uniform stream to a number of distributions. For
-covenience, the module provides an instantiated instance of a RandomGenerator
-available as ``gen``.
+Instantiate a BitGenerator and wrap it in a Generator
+which will convert the uniform stream to a number of distributions. The "bare"
+functions are kept for legacy code, they should be called with the newer API
+via ``np.random.Generator().function`` instead
==================== =========================================================
Utility functions
-==============================================================================
-random_sample Uniformly distributed floats over ``[0, 1)``.
-random Alias for `random_sample`.
+-------------------- ---------------------------------------------------------
+random Uniformly distributed floats over ``[0, 1)``
+integers Uniformly distributed integers, replaces ``randint``
bytes Uniformly distributed random bytes.
-random_integers Uniformly distributed integers in a given range.
permutation Randomly permute a sequence / generate a random sequence.
shuffle Randomly permute a sequence in place.
seed Seed the random number generator.
choice Random sample from 1-D array.
-
==================== =========================================================
==================== =========================================================
-Compatibility functions
-==============================================================================
+Compatibility
+functions - removed
+in the new API
+-------------------- ---------------------------------------------------------
rand Uniformly distributed values.
randn Normally distributed values.
ranf Uniformly distributed floating point numbers.
-randint Uniformly distributed integers in a given range.
+random_integers Uniformly distributed integers in a given range.
+ (deprecated, use ``integers(..., closed=True)`` instead)
+random_sample Alias for `random_sample`
+randint Uniformly distributed integers in a given range
==================== =========================================================
==================== =========================================================
-Univariate distributions
-==============================================================================
+Univariate
+distributions
+-------------------- ---------------------------------------------------------
beta Beta distribution over ``[0, 1]``.
binomial Binomial distribution.
chisquare :math:`\\chi^2` distribution.
@@ -63,17 +67,19 @@ weibull Weibull distribution.
zipf Zipf's distribution over ranked data.
==================== =========================================================
-==================== =========================================================
-Multivariate distributions
-==============================================================================
+==================== ==========================================================
+Multivariate
+distributions
+-------------------- ----------------------------------------------------------
dirichlet Multivariate generalization of Beta distribution.
multinomial Multivariate generalization of the binomial distribution.
multivariate_normal Multivariate generalization of the normal distribution.
-==================== =========================================================
+==================== ==========================================================
==================== =========================================================
-Standard distributions
-==============================================================================
+Standard
+distributions
+-------------------- ---------------------------------------------------------
standard_cauchy Standard Cauchy-Lorentz distribution.
standard_exponential Standard exponential distribution.
standard_gamma Standard Gamma distribution.
@@ -83,26 +89,24 @@ standard_t Standard Student's t-distribution.
==================== =========================================================
Internal functions
-==============================================================================
+-------------------- ---------------------------------------------------------
get_state Get tuple representing internal state of generator.
set_state Set state of generator.
==================== =========================================================
-==================== =========================================================
-Random Number Streams that work with RandomGenerator
-==============================================================================
+============================================= ===
+BitGenerator Streams that work with Generator
+--------------------------------------------- ---
MT19937
DSFMT
-PCG32
-PCG64
Philox
ThreeFry
ThreeFry32
Xoroshiro128
Xoroshift1024
-Xoshiro256StarStar
-Xoshiro512StarStar
-==================== =========================================================
+Xoshiro256
+Xoshiro512
+============================================= ===
"""
from __future__ import division, absolute_import, print_function
@@ -160,24 +164,20 @@ __all__ = [
from . import mtrand
from .mtrand import *
from .dsfmt import DSFMT
-from .generator import RandomGenerator
+from .generator import Generator
from .mt19937 import MT19937
-from .pcg32 import PCG32
-from .pcg64 import PCG64
from .philox import Philox
from .threefry import ThreeFry
from .threefry32 import ThreeFry32
from .xoroshiro128 import Xoroshiro128
from .xorshift1024 import Xorshift1024
-from .xoshiro256starstar import Xoshiro256StarStar
-from .xoshiro512starstar import Xoshiro512StarStar
+from .xoshiro256 import Xoshiro256
+from .xoshiro512 import Xoshiro512
from .mtrand import RandomState
-gen = RandomGenerator(Xoshiro512StarStar())
-
-__all__ += ['RandomGenerator', 'DSFMT', 'MT19937', 'PCG64', 'PCG32', 'Philox',
+__all__ += ['Generator', 'DSFMT', 'MT19937', 'Philox',
'ThreeFry', 'ThreeFry32', 'Xoroshiro128', 'Xorshift1024',
- 'Xoshiro256StarStar', 'Xoshiro512StarStar', 'RandomState', 'gen']
+ 'Xoshiro256', 'Xoshiro512', 'RandomState']
# Some aliases:
ranf = random = sample = random_sample
diff --git a/numpy/random/_pickle.py b/numpy/random/_pickle.py
index 1c365b0c7..391c565a5 100644
--- a/numpy/random/_pickle.py
+++ b/numpy/random/_pickle.py
@@ -1,103 +1,88 @@
-from .generator import RandomGenerator
-from .dsfmt import DSFMT
-from .mt19937 import MT19937
-from .pcg32 import PCG32
-from .pcg64 import PCG64
+from .mtrand import RandomState
from .philox import Philox
from .threefry import ThreeFry
from .threefry32 import ThreeFry32
from .xoroshiro128 import Xoroshiro128
from .xorshift1024 import Xorshift1024
-from .xoshiro256starstar import Xoshiro256StarStar
-from .xoshiro512starstar import Xoshiro512StarStar
-from .mtrand import RandomState
+from .xoshiro256 import Xoshiro256
+from .xoshiro512 import Xoshiro512
+
+from .dsfmt import DSFMT
+from .generator import Generator
+from .mt19937 import MT19937
-BasicRNGS = {'MT19937': MT19937,
+BitGenerators = {'MT19937': MT19937,
'DSFMT': DSFMT,
- 'PCG32': PCG32,
- 'PCG64': PCG64,
'Philox': Philox,
'ThreeFry': ThreeFry,
'ThreeFry32': ThreeFry32,
'Xorshift1024': Xorshift1024,
'Xoroshiro128': Xoroshiro128,
- 'Xoshiro256StarStar': Xoshiro256StarStar,
- 'Xoshiro512StarStar': Xoshiro512StarStar,
+ 'Xoshiro256': Xoshiro256,
+ 'Xoshiro512': Xoshiro512,
}
-def __generator_ctor(brng_name='mt19937'):
+def __generator_ctor(bit_generator_name='mt19937'):
"""
- Pickling helper function that returns a RandomGenerator object
+ Pickling helper function that returns a Generator object
Parameters
----------
- brng_name: str
- String containing the core PRNG
+ bit_generator_name: str
+ String containing the core BitGenerator
Returns
-------
- rg: RandomGenerator
- RandomGenerator using the named core PRNG
+ rg: Generator
+ Generator using the named core BitGenerator
"""
- try:
- brng_name = brng_name.decode('ascii')
- except AttributeError:
- pass
- if brng_name in PRNGS:
- brng = PRNGS[brng_name]
+ if bit_generator_name in BitGenerators:
+ bit_generator = BitGenerators[bit_generator_name]
else:
- raise ValueError(str(brng_name) + ' is not a known PRNG module.')
+ raise ValueError(str(bit_generator_name) + ' is not a known BitGenerator module.')
- return RandomGenerator(brng())
+ return Generator(bit_generator())
-def __brng_ctor(brng_name='mt19937'):
+def __bit_generator_ctor(bit_generator_name='mt19937'):
"""
- Pickling helper function that returns a basic RNG object
+ Pickling helper function that returns a bit generator object
Parameters
----------
- brng_name: str
- String containing the name of the Basic RNG
+ bit_generator_name: str
+ String containing the name of the BitGenerator
Returns
-------
- brng: BasicRNG
- Basic RNG instance
+ bit_generator: BitGenerator
+ BitGenerator instance
"""
- try:
- brng_name = brng_name.decode('ascii')
- except AttributeError:
- pass
- if brng_name in PRNGS:
- brng = PRNGS[brng_name]
+ if bit_generator_name in BitGenerators:
+ bit_generator = BitGenerators[bit_generator_name]
else:
- raise ValueError(str(brng_name) + ' is not a known PRNG module.')
+ raise ValueError(str(bit_generator_name) + ' is not a known BitGenerator module.')
- return brng()
+ return bit_generator()
-def __randomstate_ctor(brng_name='mt19937'):
+def __randomstate_ctor(bit_generator_name='mt19937'):
"""
Pickling helper function that returns a legacy RandomState-like object
Parameters
----------
- brng_name: str
- String containing the core BasicRNG
+ bit_generator_name: str
+ String containing the core BitGenerator
Returns
-------
rs: RandomState
- Legacy RandomState using the named core BasicRNG
+ Legacy RandomState using the named core BitGenerator
"""
- try:
- brng_name = brng_name.decode('ascii')
- except AttributeError:
- pass
- if brng_name in BasicRNGS:
- brng = BasicRNGS[brng_name]
+ if bit_generator_name in BitGenerators:
+ bit_generator = BitGenerators[bit_generator_name]
else:
- raise ValueError(str(brng_name) + ' is not a known BasicRNG module.')
+ raise ValueError(str(bit_generator_name) + ' is not a known BitGenerator module.')
- return RandomState(brng())
+ return RandomState(bit_generator())
diff --git a/numpy/random/bounded_integers.pxd.in b/numpy/random/bounded_integers.pxd.in
index ceb09c3c2..7a3f224dc 100644
--- a/numpy/random/bounded_integers.pxd.in
+++ b/numpy/random/bounded_integers.pxd.in
@@ -4,7 +4,7 @@ import numpy as np
cimport numpy as np
ctypedef np.npy_bool bool_t
-from .common cimport brng_t
+from .common cimport bitgen_t
cdef inline uint64_t _gen_mask(uint64_t max_val) nogil:
"""Mask generator for use in bounded random numbers"""
@@ -22,5 +22,5 @@ py:
inttypes = ('uint64','uint32','uint16','uint8','bool','int64','int32','int16','int8')
}}
{{for inttype in inttypes}}
-cdef object _rand_{{inttype}}(object low, object high, object size, bint use_masked, bint closed, brng_t *state, object lock)
+cdef object _rand_{{inttype}}(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
{{endfor}}
diff --git a/numpy/random/bounded_integers.pyx.in b/numpy/random/bounded_integers.pyx.in
index 5fbd10b4f..9f385f521 100644
--- a/numpy/random/bounded_integers.pyx.in
+++ b/numpy/random/bounded_integers.pyx.in
@@ -8,7 +8,7 @@ from .distributions cimport *
np.import_array()
-_randint_types = {'bool': (0, 2),
+_integers_types = {'bool': (0, 2),
'int8': (-2**7, 2**7),
'int16': (-2**15, 2**15),
'int32': (-2**31, 2**31),
@@ -31,7 +31,7 @@ type_info = (('uint32', 'uint32', 'uint64', 'NPY_UINT64', 0, 0, 0, '0X100000000U
{{ py: otype = nptype + '_' if nptype == 'bool' else nptype }}
cdef object _rand_{{nptype}}_broadcast(np.ndarray low, np.ndarray high, object size,
bint use_masked, bint closed,
- brng_t *state, object lock):
+ bitgen_t *state, object lock):
"""
Array path for smaller integer types
@@ -107,7 +107,7 @@ big_type_info = (('uint64', 'uint64', 'NPY_UINT64', '0x0ULL', '0xFFFFFFFFFFFFFFF
{{ py: otype = nptype}}
cdef object _rand_{{nptype}}_broadcast(object low, object high, object size,
bint use_masked, bint closed,
- brng_t *state, object lock):
+ bitgen_t *state, object lock):
"""
Array path for 64-bit integer types
@@ -210,7 +210,7 @@ type_info = (('uint64', 'uint64', '0x0ULL', '0xFFFFFFFFFFFFFFFFULL'),
{{ py: otype = nptype + '_' if nptype == 'bool' else nptype }}
cdef object _rand_{{nptype}}(object low, object high, object size,
bint use_masked, bint closed,
- brng_t *state, object lock):
+ bitgen_t *state, object lock):
"""
_rand_{{nptype}}(low, high, size, use_masked, *state, lock)
@@ -238,8 +238,8 @@ cdef object _rand_{{nptype}}(object low, object high, object size,
If True then rejection sampling with a range mask is used else Lemire's algorithm is used.
closed : bool
If True then sample from [low, high]. If False, sample [low, high)
- state : basic random state
- State to use in the core random number generators
+ state : bit generator
+ Bit generator state to use in the core random number generators
lock : threading.Lock
Lock to prevent multiple using a single generator simultaneously
diff --git a/numpy/random/common.pxd b/numpy/random/common.pxd
index f6748e5aa..4f7c8c903 100644
--- a/numpy/random/common.pxd
+++ b/numpy/random/common.pxd
@@ -5,7 +5,7 @@ from libc.stdint cimport (uint8_t, uint16_t, uint32_t, uint64_t,
uintptr_t)
from libc.math cimport sqrt
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
import numpy as np
cimport numpy as np
@@ -26,10 +26,10 @@ cdef enum ConstraintType:
ctypedef ConstraintType constraint_type
-cdef object benchmark(brng_t *brng, object lock, Py_ssize_t cnt, object method)
-cdef object random_raw(brng_t *brng, object lock, object size, object output)
-cdef object prepare_cffi(brng_t *brng)
-cdef object prepare_ctypes(brng_t *brng)
+cdef object benchmark(bitgen_t *bitgen, object lock, Py_ssize_t cnt, object method)
+cdef object random_raw(bitgen_t *bitgen, object lock, object size, object output)
+cdef object prepare_cffi(bitgen_t *bitgen)
+cdef object prepare_ctypes(bitgen_t *bitgen)
cdef int check_constraint(double val, object name, constraint_type cons) except -1
cdef int check_array_constraint(np.ndarray val, object name, constraint_type cons) except -1
@@ -39,14 +39,14 @@ cdef extern from "src/aligned_malloc/aligned_malloc.h":
cdef void *PyArray_calloc_aligned(size_t n, size_t s)
cdef void PyArray_free_aligned(void *p)
-ctypedef double (*random_double_fill)(brng_t *state, np.npy_intp count, double* out) nogil
+ctypedef double (*random_double_fill)(bitgen_t *state, np.npy_intp count, double* out) nogil
ctypedef double (*random_double_0)(void *state) nogil
ctypedef double (*random_double_1)(void *state, double a) nogil
ctypedef double (*random_double_2)(void *state, double a, double b) nogil
ctypedef double (*random_double_3)(void *state, double a, double b, double c) nogil
-ctypedef float (*random_float_0)(brng_t *state) nogil
-ctypedef float (*random_float_1)(brng_t *state, float a) nogil
+ctypedef float (*random_float_0)(bitgen_t *state) nogil
+ctypedef float (*random_float_1)(bitgen_t *state, float a) nogil
ctypedef int64_t (*random_uint_0)(void *state) nogil
ctypedef int64_t (*random_uint_d)(void *state, double a) nogil
@@ -55,22 +55,22 @@ ctypedef int64_t (*random_uint_di)(void *state, double a, uint64_t b) nogil
ctypedef int64_t (*random_uint_i)(void *state, int64_t a) nogil
ctypedef int64_t (*random_uint_iii)(void *state, int64_t a, int64_t b, int64_t c) nogil
-ctypedef uint32_t (*random_uint_0_32)(brng_t *state) nogil
-ctypedef uint32_t (*random_uint_1_i_32)(brng_t *state, uint32_t a) nogil
+ctypedef uint32_t (*random_uint_0_32)(bitgen_t *state) nogil
+ctypedef uint32_t (*random_uint_1_i_32)(bitgen_t *state, uint32_t a) nogil
-ctypedef int32_t (*random_int_2_i_32)(brng_t *state, int32_t a, int32_t b) nogil
-ctypedef int64_t (*random_int_2_i)(brng_t *state, int64_t a, int64_t b) nogil
+ctypedef int32_t (*random_int_2_i_32)(bitgen_t *state, int32_t a, int32_t b) nogil
+ctypedef int64_t (*random_int_2_i)(bitgen_t *state, int64_t a, int64_t b) nogil
cdef double kahan_sum(double *darr, np.npy_intp n)
cdef inline double uint64_to_double(uint64_t rnd) nogil:
return (rnd >> 11) * (1.0 / 9007199254740992.0)
-cdef object double_fill(void *func, brng_t *state, object size, object lock, object out)
+cdef object double_fill(void *func, bitgen_t *state, object size, object lock, object out)
-cdef object float_fill(void *func, brng_t *state, object size, object lock, object out)
+cdef object float_fill(void *func, bitgen_t *state, object size, object lock, object out)
-cdef object float_fill_from_double(void *func, brng_t *state, object size, object lock, object out)
+cdef object float_fill_from_double(void *func, bitgen_t *state, object size, object lock, object out)
cdef np.ndarray int_to_array(object value, object name, object bits, object uint_size)
@@ -86,7 +86,7 @@ cdef object disc(void *func, void *state, object size, object lock,
object b, object b_name, constraint_type b_constraint,
object c, object c_name, constraint_type c_constraint)
-cdef object cont_f(void *func, brng_t *state, object size, object lock,
+cdef object cont_f(void *func, bitgen_t *state, object size, object lock,
object a, object a_name, constraint_type a_constraint,
object out)
diff --git a/numpy/random/common.pyx b/numpy/random/common.pyx
index d5918c3a9..2fa854807 100644
--- a/numpy/random/common.pyx
+++ b/numpy/random/common.pyx
@@ -11,25 +11,26 @@ from .common cimport *
np.import_array()
interface = namedtuple('interface', ['state_address', 'state', 'next_uint64',
- 'next_uint32', 'next_double', 'brng'])
+ 'next_uint32', 'next_double',
+ 'bit_generator'])
-cdef object benchmark(brng_t *brng, object lock, Py_ssize_t cnt, object method):
- """Benchmark command used by BasicRNG"""
+cdef object benchmark(bitgen_t *bitgen, object lock, Py_ssize_t cnt, object method):
+ """Benchmark command used by BitGenerator"""
cdef Py_ssize_t i
if method==u'uint64':
with lock, nogil:
for i in range(cnt):
- brng.next_uint64(brng.state)
+ bitgen.next_uint64(bitgen.state)
elif method==u'double':
with lock, nogil:
for i in range(cnt):
- brng.next_double(brng.state)
+ bitgen.next_double(bitgen.state)
else:
raise ValueError('Unknown method')
-cdef object random_raw(brng_t *brng, object lock, object size, object output):
+cdef object random_raw(bitgen_t *bitgen, object lock, object size, object output):
"""
random_raw(self, size=None)
@@ -65,17 +66,17 @@ cdef object random_raw(brng_t *brng, object lock, object size, object output):
if not output:
if size is None:
with lock:
- brng.next_raw(brng.state)
+ bitgen.next_raw(bitgen.state)
return None
n = np.asarray(size).sum()
with lock, nogil:
for i in range(n):
- brng.next_raw(brng.state)
+ bitgen.next_raw(bitgen.state)
return None
if size is None:
with lock:
- return brng.next_raw(brng.state)
+ return bitgen.next_raw(bitgen.state)
randoms = <np.ndarray>np.empty(size, np.uint64)
randoms_data = <uint64_t*>np.PyArray_DATA(randoms)
@@ -83,29 +84,29 @@ cdef object random_raw(brng_t *brng, object lock, object size, object output):
with lock, nogil:
for i in range(n):
- randoms_data[i] = brng.next_raw(brng.state)
+ randoms_data[i] = bitgen.next_raw(bitgen.state)
return randoms
-cdef object prepare_cffi(brng_t *brng):
+cdef object prepare_cffi(bitgen_t *bitgen):
"""
- Bundles the interfaces to interact with a Basic RNG using cffi
+ Bundles the interfaces to interact with a BitGenerator using cffi
Parameters
----------
- brng : pointer
- A pointer to a Basic RNG instance
+ bitgen : pointer
+ A pointer to a BitGenerator instance
Returns
-------
interface : namedtuple
- The functions required to interface with the Basic RNG using cffi
+ The functions required to interface with the BitGenerator using cffi
* state_address - Memory address of the state struct
* state - pointer to the state struct
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bit_generator - pointer to the BitGenerator struct
"""
try:
import cffi
@@ -113,49 +114,49 @@ cdef object prepare_cffi(brng_t *brng):
raise ImportError('cffi cannot be imported.')
ffi = cffi.FFI()
- _cffi = interface(<uintptr_t>brng.state,
- ffi.cast('void *', <uintptr_t>brng.state),
- ffi.cast('uint64_t (*)(void *)', <uintptr_t>brng.next_uint64),
- ffi.cast('uint32_t (*)(void *)', <uintptr_t>brng.next_uint32),
- ffi.cast('double (*)(void *)', <uintptr_t>brng.next_double),
- ffi.cast('void *', <uintptr_t>brng))
+ _cffi = interface(<uintptr_t>bitgen.state,
+ ffi.cast('void *', <uintptr_t>bitgen.state),
+ ffi.cast('uint64_t (*)(void *)', <uintptr_t>bitgen.next_uint64),
+ ffi.cast('uint32_t (*)(void *)', <uintptr_t>bitgen.next_uint32),
+ ffi.cast('double (*)(void *)', <uintptr_t>bitgen.next_double),
+ ffi.cast('void *', <uintptr_t>bitgen))
return _cffi
-cdef object prepare_ctypes(brng_t *brng):
+cdef object prepare_ctypes(bitgen_t *bitgen):
"""
- Bundles the interfaces to interact with a Basic RNG using ctypes
+ Bundles the interfaces to interact with a BitGenerator using ctypes
Parameters
----------
- brng : pointer
- A pointer to a Basic RNG instance
+ bitgen : pointer
+ A pointer to a BitGenerator instance
Returns
-------
interface : namedtuple
- The functions required to interface with the Basic RNG using ctypes:
+ The functions required to interface with the BitGenerator using ctypes:
* state_address - Memory address of the state struct
* state - pointer to the state struct
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bit_generator - pointer to the BitGenerator struct
"""
import ctypes
- _ctypes = interface(<uintptr_t>brng.state,
- ctypes.c_void_p(<uintptr_t>brng.state),
- ctypes.cast(<uintptr_t>brng.next_uint64,
+ _ctypes = interface(<uintptr_t>bitgen.state,
+ ctypes.c_void_p(<uintptr_t>bitgen.state),
+ ctypes.cast(<uintptr_t>bitgen.next_uint64,
ctypes.CFUNCTYPE(ctypes.c_uint64,
ctypes.c_void_p)),
- ctypes.cast(<uintptr_t>brng.next_uint32,
+ ctypes.cast(<uintptr_t>bitgen.next_uint32,
ctypes.CFUNCTYPE(ctypes.c_uint32,
ctypes.c_void_p)),
- ctypes.cast(<uintptr_t>brng.next_double,
+ ctypes.cast(<uintptr_t>bitgen.next_double,
ctypes.CFUNCTYPE(ctypes.c_double,
ctypes.c_void_p)),
- ctypes.c_void_p(<uintptr_t>brng))
+ ctypes.c_void_p(<uintptr_t>bitgen))
return _ctypes
cdef double kahan_sum(double *darr, np.npy_intp n):
@@ -218,7 +219,7 @@ cdef check_output(object out, object dtype, object size):
raise ValueError('size must match out.shape when used together')
-cdef object double_fill(void *func, brng_t *state, object size, object lock, object out):
+cdef object double_fill(void *func, bitgen_t *state, object size, object lock, object out):
cdef random_double_fill random_func = (<random_double_fill>func)
cdef double out_val
cdef double *out_array_data
@@ -242,7 +243,7 @@ cdef object double_fill(void *func, brng_t *state, object size, object lock, obj
random_func(state, n, out_array_data)
return out_array
-cdef object float_fill(void *func, brng_t *state, object size, object lock, object out):
+cdef object float_fill(void *func, bitgen_t *state, object size, object lock, object out):
cdef random_float_0 random_func = (<random_float_0>func)
cdef float *out_array_data
cdef np.ndarray out_array
@@ -265,7 +266,7 @@ cdef object float_fill(void *func, brng_t *state, object size, object lock, obje
out_array_data[i] = random_func(state)
return out_array
-cdef object float_fill_from_double(void *func, brng_t *state, object size, object lock, object out):
+cdef object float_fill_from_double(void *func, bitgen_t *state, object size, object lock, object out):
cdef random_double_0 random_func = (<random_double_0>func)
cdef float *out_array_data
cdef np.ndarray out_array
@@ -871,7 +872,7 @@ cdef object disc(void *func, void *state, object size, object lock,
return randoms
-cdef object cont_broadcast_1_f(void *func, brng_t *state, object size, object lock,
+cdef object cont_broadcast_1_f(void *func, bitgen_t *state, object size, object lock,
np.ndarray a_arr, object a_name, constraint_type a_constraint,
object out):
@@ -907,7 +908,7 @@ cdef object cont_broadcast_1_f(void *func, brng_t *state, object size, object lo
return randoms
-cdef object cont_f(void *func, brng_t *state, object size, object lock,
+cdef object cont_f(void *func, bitgen_t *state, object size, object lock,
object a, object a_name, constraint_type a_constraint,
object out):
diff --git a/numpy/random/distributions.pxd b/numpy/random/distributions.pxd
index 841fd3253..5d6f08417 100644
--- a/numpy/random/distributions.pxd
+++ b/numpy/random/distributions.pxd
@@ -5,7 +5,7 @@ from libc.stdint cimport (uint8_t, uint16_t, uint32_t, uint64_t,
import numpy as np
cimport numpy as np
-cdef extern from "distributions/distributions.h":
+cdef extern from "src/distributions/distributions.h":
struct s_binomial_t:
int has_binomial
@@ -28,122 +28,122 @@ cdef extern from "distributions/distributions.h":
ctypedef s_binomial_t binomial_t
- struct brng:
+ struct bitgen:
void *state
uint64_t (*next_uint64)(void *st) nogil
uint32_t (*next_uint32)(void *st) nogil
double (*next_double)(void *st) nogil
uint64_t (*next_raw)(void *st) nogil
- ctypedef brng brng_t
-
- double random_double(brng_t *brng_state) nogil
- void random_double_fill(brng_t* brng_state, np.npy_intp cnt, double *out) nogil
- double random_standard_exponential(brng_t *brng_state) nogil
- void random_standard_exponential_fill(brng_t *brng_state, np.npy_intp cnt, double *out) nogil
- double random_standard_exponential_zig(brng_t *brng_state) nogil
- void random_standard_exponential_zig_fill(brng_t *brng_state, np.npy_intp cnt, double *out) nogil
- double random_gauss_zig(brng_t* brng_state) nogil
- void random_gauss_zig_fill(brng_t *brng_state, np.npy_intp count, double *out) nogil
- double random_standard_gamma_zig(brng_t *brng_state, double shape) nogil
-
- float random_float(brng_t *brng_state) nogil
- float random_standard_exponential_f(brng_t *brng_state) nogil
- float random_standard_exponential_zig_f(brng_t *brng_state) nogil
- float random_gauss_zig_f(brng_t* brng_state) nogil
- float random_standard_gamma_f(brng_t *brng_state, float shape) nogil
- float random_standard_gamma_zig_f(brng_t *brng_state, float shape) nogil
-
- int64_t random_positive_int64(brng_t *brng_state) nogil
- int32_t random_positive_int32(brng_t *brng_state) nogil
- int64_t random_positive_int(brng_t *brng_state) nogil
- uint64_t random_uint(brng_t *brng_state) nogil
-
- double random_normal_zig(brng_t *brng_state, double loc, double scale) nogil
-
- double random_gamma(brng_t *brng_state, double shape, double scale) nogil
- float random_gamma_float(brng_t *brng_state, float shape, float scale) nogil
-
- double random_exponential(brng_t *brng_state, double scale) nogil
- double random_uniform(brng_t *brng_state, double lower, double range) nogil
- double random_beta(brng_t *brng_state, double a, double b) nogil
- double random_chisquare(brng_t *brng_state, double df) nogil
- double random_f(brng_t *brng_state, double dfnum, double dfden) nogil
- double random_standard_cauchy(brng_t *brng_state) nogil
- double random_pareto(brng_t *brng_state, double a) nogil
- double random_weibull(brng_t *brng_state, double a) nogil
- double random_power(brng_t *brng_state, double a) nogil
- double random_laplace(brng_t *brng_state, double loc, double scale) nogil
- double random_gumbel(brng_t *brng_state, double loc, double scale) nogil
- double random_logistic(brng_t *brng_state, double loc, double scale) nogil
- double random_lognormal(brng_t *brng_state, double mean, double sigma) nogil
- double random_rayleigh(brng_t *brng_state, double mode) nogil
- double random_standard_t(brng_t *brng_state, double df) nogil
- double random_noncentral_chisquare(brng_t *brng_state, double df,
+ ctypedef bitgen bitgen_t
+
+ double random_double(bitgen_t *bitgen_state) nogil
+ void random_double_fill(bitgen_t* bitgen_state, np.npy_intp cnt, double *out) nogil
+ double random_standard_exponential(bitgen_t *bitgen_state) nogil
+ void random_standard_exponential_fill(bitgen_t *bitgen_state, np.npy_intp cnt, double *out) nogil
+ double random_standard_exponential_zig(bitgen_t *bitgen_state) nogil
+ void random_standard_exponential_zig_fill(bitgen_t *bitgen_state, np.npy_intp cnt, double *out) nogil
+ double random_gauss_zig(bitgen_t* bitgen_state) nogil
+ void random_gauss_zig_fill(bitgen_t *bitgen_state, np.npy_intp count, double *out) nogil
+ double random_standard_gamma_zig(bitgen_t *bitgen_state, double shape) nogil
+
+ float random_float(bitgen_t *bitgen_state) nogil
+ float random_standard_exponential_f(bitgen_t *bitgen_state) nogil
+ float random_standard_exponential_zig_f(bitgen_t *bitgen_state) nogil
+ float random_gauss_zig_f(bitgen_t* bitgen_state) nogil
+ float random_standard_gamma_f(bitgen_t *bitgen_state, float shape) nogil
+ float random_standard_gamma_zig_f(bitgen_t *bitgen_state, float shape) nogil
+
+ int64_t random_positive_int64(bitgen_t *bitgen_state) nogil
+ int32_t random_positive_int32(bitgen_t *bitgen_state) nogil
+ int64_t random_positive_int(bitgen_t *bitgen_state) nogil
+ uint64_t random_uint(bitgen_t *bitgen_state) nogil
+
+ double random_normal_zig(bitgen_t *bitgen_state, double loc, double scale) nogil
+
+ double random_gamma(bitgen_t *bitgen_state, double shape, double scale) nogil
+ float random_gamma_float(bitgen_t *bitgen_state, float shape, float scale) nogil
+
+ double random_exponential(bitgen_t *bitgen_state, double scale) nogil
+ double random_uniform(bitgen_t *bitgen_state, double lower, double range) nogil
+ double random_beta(bitgen_t *bitgen_state, double a, double b) nogil
+ double random_chisquare(bitgen_t *bitgen_state, double df) nogil
+ double random_f(bitgen_t *bitgen_state, double dfnum, double dfden) nogil
+ double random_standard_cauchy(bitgen_t *bitgen_state) nogil
+ double random_pareto(bitgen_t *bitgen_state, double a) nogil
+ double random_weibull(bitgen_t *bitgen_state, double a) nogil
+ double random_power(bitgen_t *bitgen_state, double a) nogil
+ double random_laplace(bitgen_t *bitgen_state, double loc, double scale) nogil
+ double random_gumbel(bitgen_t *bitgen_state, double loc, double scale) nogil
+ double random_logistic(bitgen_t *bitgen_state, double loc, double scale) nogil
+ double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma) nogil
+ double random_rayleigh(bitgen_t *bitgen_state, double mode) nogil
+ double random_standard_t(bitgen_t *bitgen_state, double df) nogil
+ double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
double nonc) nogil
- double random_noncentral_f(brng_t *brng_state, double dfnum,
+ double random_noncentral_f(bitgen_t *bitgen_state, double dfnum,
double dfden, double nonc) nogil
- double random_wald(brng_t *brng_state, double mean, double scale) nogil
- double random_vonmises(brng_t *brng_state, double mu, double kappa) nogil
- double random_triangular(brng_t *brng_state, double left, double mode,
+ double random_wald(bitgen_t *bitgen_state, double mean, double scale) nogil
+ double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa) nogil
+ double random_triangular(bitgen_t *bitgen_state, double left, double mode,
double right) nogil
- int64_t random_poisson(brng_t *brng_state, double lam) nogil
- int64_t random_negative_binomial(brng_t *brng_state, double n, double p) nogil
- int64_t random_binomial(brng_t *brng_state, double p, int64_t n, binomial_t *binomial) nogil
- int64_t random_logseries(brng_t *brng_state, double p) nogil
- int64_t random_geometric_search(brng_t *brng_state, double p) nogil
- int64_t random_geometric_inversion(brng_t *brng_state, double p) nogil
- int64_t random_geometric(brng_t *brng_state, double p) nogil
- int64_t random_zipf(brng_t *brng_state, double a) nogil
- int64_t random_hypergeometric(brng_t *brng_state, int64_t good, int64_t bad,
+ int64_t random_poisson(bitgen_t *bitgen_state, double lam) nogil
+ int64_t random_negative_binomial(bitgen_t *bitgen_state, double n, double p) nogil
+ int64_t random_binomial(bitgen_t *bitgen_state, double p, int64_t n, binomial_t *binomial) nogil
+ int64_t random_logseries(bitgen_t *bitgen_state, double p) nogil
+ int64_t random_geometric_search(bitgen_t *bitgen_state, double p) nogil
+ int64_t random_geometric_inversion(bitgen_t *bitgen_state, double p) nogil
+ int64_t random_geometric(bitgen_t *bitgen_state, double p) nogil
+ int64_t random_zipf(bitgen_t *bitgen_state, double a) nogil
+ int64_t random_hypergeometric(bitgen_t *bitgen_state, int64_t good, int64_t bad,
int64_t sample) nogil
- uint64_t random_interval(brng_t *brng_state, uint64_t max) nogil
+ uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max) nogil
# Generate random uint64 numbers in closed interval [off, off + rng].
- uint64_t random_bounded_uint64(brng_t *brng_state,
+ uint64_t random_bounded_uint64(bitgen_t *bitgen_state,
uint64_t off, uint64_t rng,
uint64_t mask, bint use_masked) nogil
# Generate random uint32 numbers in closed interval [off, off + rng].
- uint32_t random_buffered_bounded_uint32(brng_t *brng_state,
+ uint32_t random_buffered_bounded_uint32(bitgen_t *bitgen_state,
uint32_t off, uint32_t rng,
uint32_t mask, bint use_masked,
int *bcnt, uint32_t *buf) nogil
- uint16_t random_buffered_bounded_uint16(brng_t *brng_state,
+ uint16_t random_buffered_bounded_uint16(bitgen_t *bitgen_state,
uint16_t off, uint16_t rng,
uint16_t mask, bint use_masked,
int *bcnt, uint32_t *buf) nogil
- uint8_t random_buffered_bounded_uint8(brng_t *brng_state,
+ uint8_t random_buffered_bounded_uint8(bitgen_t *bitgen_state,
uint8_t off, uint8_t rng,
uint8_t mask, bint use_masked,
int *bcnt, uint32_t *buf) nogil
- np.npy_bool random_buffered_bounded_bool(brng_t *brng_state,
+ np.npy_bool random_buffered_bounded_bool(bitgen_t *bitgen_state,
np.npy_bool off, np.npy_bool rng,
np.npy_bool mask, bint use_masked,
int *bcnt, uint32_t *buf) nogil
- void random_bounded_uint64_fill(brng_t *brng_state,
+ void random_bounded_uint64_fill(bitgen_t *bitgen_state,
uint64_t off, uint64_t rng, np.npy_intp cnt,
bint use_masked,
uint64_t *out) nogil
- void random_bounded_uint32_fill(brng_t *brng_state,
+ void random_bounded_uint32_fill(bitgen_t *bitgen_state,
uint32_t off, uint32_t rng, np.npy_intp cnt,
bint use_masked,
uint32_t *out) nogil
- void random_bounded_uint16_fill(brng_t *brng_state,
+ void random_bounded_uint16_fill(bitgen_t *bitgen_state,
uint16_t off, uint16_t rng, np.npy_intp cnt,
bint use_masked,
uint16_t *out) nogil
- void random_bounded_uint8_fill(brng_t *brng_state,
+ void random_bounded_uint8_fill(bitgen_t *bitgen_state,
uint8_t off, uint8_t rng, np.npy_intp cnt,
bint use_masked,
uint8_t *out) nogil
- void random_bounded_bool_fill(brng_t *brng_state,
+ void random_bounded_bool_fill(bitgen_t *bitgen_state,
np.npy_bool off, np.npy_bool rng, np.npy_intp cnt,
bint use_masked,
np.npy_bool *out) nogil
- void random_multinomial(brng_t *brng_state, int64_t n, int64_t *mnix,
+ void random_multinomial(bitgen_t *bitgen_state, int64_t n, int64_t *mnix,
double *pix, np.npy_intp d, binomial_t *binomial) nogil
diff --git a/numpy/random/dsfmt.pyx b/numpy/random/dsfmt.pyx
index 709c2c8e8..cd6d92153 100644
--- a/numpy/random/dsfmt.pyx
+++ b/numpy/random/dsfmt.pyx
@@ -1,6 +1,6 @@
import operator
-from libc.stdlib cimport malloc, free
from cpython.pycapsule cimport PyCapsule_New
+from libc.string cimport memcpy
try:
from threading import Lock
@@ -11,7 +11,7 @@ import numpy as np
cimport numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy
np.import_array()
@@ -76,59 +76,61 @@ cdef class DSFMT:
Parameters
----------
seed : {None, int, array_like}, optional
- Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**32-1], array of integers in
- [0, 2**32-1] or ``None`` (the default). If `seed` is ``None``,
- then ``DSFMT`` will try to read entropy from ``/dev/urandom``
- (or the Windows analog) if available to produce a 32-bit
- seed. If unavailable, a 32-bit hash of the time and process
- ID is used.
+ Random seed used to initialize the pseudo-random number generator. Can
+ be any integer between 0 and 2**32 - 1 inclusive, an array (or other
+ sequence) of unsigned 32-bit integers, or ``None`` (the default). If
+ `seed` is ``None``, a 32-bit unsigned integer is read from
+ ``/dev/urandom`` (or the Windows analog) if available. If unavailable,
+ a 32-bit hash of the time and process ID is used.
Notes
-----
- ``DSFMT`` directly provides generators for doubles, and unsigned 32 and 64-
- bit integers [1]_ . These are not directly available and must be consumed
- via a ``RandomGenerator`` object.
+ ``DSFMT`` provides a capsule containing function pointers that produce
+ doubles, and unsigned 32 and 64- bit integers [1]_ . These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
The Python stdlib module "random" also contains a Mersenne Twister
pseudo-random number generator.
- **Parallel Features**
-
- ``DSFMT`` can be used in parallel applications by calling the method
- ``jump`` which advances the state as-if :math:`2^{128}` random numbers
- have been generated [2]_. This allows the original sequence to be split
- so that distinct segments can be used in each worker process. All
- generators should be initialized with the same seed to ensure that the
- segments come from the same sequence.
-
- >>> from numpy.random.entropy import random_entropy
- >>> from numpy.random import RandomGenerator, DSFMT
- >>> seed = random_entropy()
- >>> rs = [RandomGenerator(DSFMT(seed)) for _ in range(10)]
- # Advance each DSFMT instance by i jumps
- >>> for i in range(10):
- ... rs[i].brng.jump()
-
**State and Seeding**
- The ``DSFMT`` state vector consists of a 384 element array of
- 64-bit unsigned integers plus a single integer value between 0 and 382
- indicating the current position within the main array. The implementation
+ The ``DSFMT`` state vector consists of a 384 element array of 64-bit
+ unsigned integers plus a single integer value between 0 and 382
+ indicating the current position within the main array. The implementation
used here augments this with a 382 element array of doubles which are used
to efficiently access the random numbers produced by the dSFMT generator.
- ``DSFMT`` is seeded using either a single 32-bit unsigned integer
- or a vector of 32-bit unsigned integers. In either case, the input seed is
- used as an input (or inputs) for a hashing function, and the output of the
+ ``DSFMT`` is seeded using either a single 32-bit unsigned integer or a
+ vector of 32-bit unsigned integers. In either case, the input seed is used
+ as an input (or inputs) for a hashing function, and the output of the
hashing function is used as the initial state. Using a single 32-bit value
for the seed can only initialize a small range of the possible initial
state values.
+ **Parallel Features**
+
+ ``DSFMT`` can be used in parallel applications by calling the method
+ ``jumped`` which advances the state as-if :math:`2^{128}` random numbers
+ have been generated [2]_. This allows the original sequence to be split
+ so that distinct segments can be used in each worker process. All
+ generators should be chained to ensure that the segments come from the same
+ sequence.
+
+ >>> from numpy.random.entropy import random_entropy
+ >>> from numpy.random import Generator, DSFMT
+ >>> seed = random_entropy()
+ >>> bit_generator = DSFMT(seed)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
+
**Compatibility Guarantee**
- ``DSFMT`` does makes a guarantee that a fixed seed and will always
- produce the same results.
+ ``DSFMT`` makes a guarantee that a fixed seed and will always produce
+ the same random integer stream.
References
----------
@@ -139,34 +141,30 @@ cdef class DSFMT:
Jump Ahead Algorithm for Linear Recurrences in a Polynomial Space",
Sequences and Their Applications - SETA, 290--298, 2008.
"""
- cdef dsfmt_state *rng_state
- cdef brng_t *_brng
+ cdef dsfmt_state rng_state
+ cdef bitgen_t _bitgen
cdef public object capsule
- cdef public object _cffi
- cdef public object _ctypes
- cdef public object _generator
+ cdef object _cffi
+ cdef object _ctypes
cdef public object lock
def __init__(self, seed=None):
- self.rng_state = <dsfmt_state *>malloc(sizeof(dsfmt_state))
self.rng_state.state = <dsfmt_t *>PyArray_malloc_aligned(sizeof(dsfmt_t))
self.rng_state.buffered_uniforms = <double *>PyArray_calloc_aligned(DSFMT_N64, sizeof(double))
self.rng_state.buffer_loc = DSFMT_N64
- self._brng = <brng_t *>malloc(sizeof(brng_t))
self.seed(seed)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &dsfmt_uint64
- self._brng.next_uint32 = &dsfmt_uint32
- self._brng.next_double = &dsfmt_double
- self._brng.next_raw = &dsfmt_raw
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &dsfmt_uint64
+ self._bitgen.next_uint32 = &dsfmt_uint32
+ self._bitgen.next_double = &dsfmt_double
+ self._bitgen.next_raw = &dsfmt_raw
+ cdef const char *name = "BitGenerator"
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
self._cffi = None
self._ctypes = None
- self._generator = None
# Pickling support:
def __getstate__(self):
@@ -176,18 +174,14 @@ cdef class DSFMT:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
def __dealloc__(self):
- if self.rng_state:
+ if self.rng_state.state:
PyArray_free_aligned(self.rng_state.state)
+ if self.rng_state.buffered_uniforms:
PyArray_free_aligned(self.rng_state.buffered_uniforms)
- free(self.rng_state)
- if self._brng:
- free(self._brng)
cdef _reset_state_variables(self):
self.rng_state.buffer_loc = DSFMT_N64
@@ -196,7 +190,7 @@ cdef class DSFMT:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -221,10 +215,10 @@ cdef class DSFMT:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None):
"""
@@ -274,28 +268,49 @@ cdef class DSFMT:
# Clear the buffer
self._reset_state_variables()
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**128 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
- Number of times to jump the state of the brng.
-
- Returns
- -------
- self : DSFMT
- PRNG jumped iter times
+ Number of times to jump the state of the rng.
"""
cdef np.npy_intp i
for i in range(iter):
- dsfmt_jump(self.rng_state)
+ dsfmt_jump(&self.rng_state)
# Clear the buffer
self._reset_state_variables()
- return self
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(128 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
+
+ Returns
+ -------
+ bit_generator : DSFMT
+ New instance of generator jumped iter times
+ """
+ cdef DSFMT bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
@property
def state(self):
@@ -321,7 +336,7 @@ cdef class DSFMT:
buffered_uniforms = np.empty(DSFMT_N64, dtype=np.double)
for i in range(DSFMT_N64):
buffered_uniforms[i] = self.rng_state.buffered_uniforms[i]
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
'state': {'state': np.asarray(state),
'idx': self.rng_state.state.idx},
'buffer_loc': self.rng_state.buffer_loc,
@@ -332,8 +347,8 @@ cdef class DSFMT:
cdef Py_ssize_t i, j, loc = 0
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
state = value['state']['state']
@@ -362,10 +377,10 @@ cdef class DSFMT:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -384,24 +399,9 @@ cdef class DSFMT:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator # ignore
- Random generator used this instance as the basic RNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/entropy.pyx b/numpy/random/entropy.pyx
index 0e429e9f2..72b0a9851 100644
--- a/numpy/random/entropy.pyx
+++ b/numpy/random/entropy.pyx
@@ -28,7 +28,7 @@ def seed_by_array(object seed, Py_ssize_t n):
Parameters
----------
- seed: array, 1d, uint64
+ seed: ndarray, 1d, uint64
Array to use. If seed is a scalar, promote to array.
n : int
Number of 64-bit unsigned integers required
@@ -106,8 +106,9 @@ def random_entropy(size=None, source='system'):
Returns
-------
- entropy : scalar or ndarray
- Entropy bits in 32-bit unsigned integers
+ entropy : scalar or array
+ Entropy bits in 32-bit unsigned integers. A scalar is returned if size
+ is `None`.
Notes
-----
@@ -117,7 +118,7 @@ def random_entropy(size=None, source='system'):
This function reads from the system entropy pool and so samples are
not reproducible. In particular, it does *NOT* make use of a
- basic RNG, and so ``seed`` and setting ``state`` have no
+ BitGenerator, and so ``seed`` and setting ``state`` have no
effect.
Raises RuntimeError if the command fails.
diff --git a/numpy/random/examples/cython/extending.pyx b/numpy/random/examples/cython/extending.pyx
index b472312b4..858bf2f62 100644
--- a/numpy/random/examples/cython/extending.pyx
+++ b/numpy/random/examples/cython/extending.pyx
@@ -1,4 +1,6 @@
+#!/usr/bin/env python
#cython: language_level=3
+
from libc.stdint cimport uint32_t
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
@@ -6,16 +8,16 @@ import numpy as np
cimport numpy as np
cimport cython
-from numpy.random.randomgen.common cimport brng_t
-from numpy.random.randomgen import Xoroshiro128
+from numpy.random.common cimport bitgen_t
+from numpy.random import Xoroshiro128
np.import_array()
def uniform_mean(Py_ssize_t N):
cdef Py_ssize_t i
- cdef brng_t *rng
- cdef const char *capsule_name = "BasicRNG"
+ cdef bitgen_t *rng
+ cdef const char *capsule_name = "BitGenerator"
cdef double[::1] random_values
cdef np.ndarray randoms
@@ -23,7 +25,7 @@ def uniform_mean(Py_ssize_t N):
capsule = x.capsule
if not PyCapsule_IsValid(capsule, capsule_name):
raise ValueError("Invalid pointer to anon_func_state")
- rng = <brng_t *> PyCapsule_GetPointer(capsule, capsule_name)
+ rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
random_values = np.empty(N)
for i in range(N):
random_values[i] = rng.next_double(rng.state)
@@ -31,7 +33,7 @@ def uniform_mean(Py_ssize_t N):
return randoms.mean()
-cdef uint32_t bounded_uint(uint32_t lb, uint32_t ub, brng_t *rng):
+cdef uint32_t bounded_uint(uint32_t lb, uint32_t ub, bitgen_t *rng):
cdef uint32_t mask, delta, val
mask = delta = ub - lb
mask |= mask >> 1
@@ -51,9 +53,9 @@ cdef uint32_t bounded_uint(uint32_t lb, uint32_t ub, brng_t *rng):
@cython.wraparound(False)
def bounded_uints(uint32_t lb, uint32_t ub, Py_ssize_t n):
cdef Py_ssize_t i
- cdef brng_t *rng
+ cdef bitgen_t *rng
cdef uint32_t[::1] out
- cdef const char *capsule_name = "BasicRNG"
+ cdef const char *capsule_name = "BitGenerator"
x = Xoroshiro128()
out = np.empty(n, dtype=np.uint32)
@@ -61,7 +63,7 @@ def bounded_uints(uint32_t lb, uint32_t ub, Py_ssize_t n):
if not PyCapsule_IsValid(capsule, capsule_name):
raise ValueError("Invalid pointer to anon_func_state")
- rng = <brng_t *>PyCapsule_GetPointer(capsule, capsule_name)
+ rng = <bitgen_t *>PyCapsule_GetPointer(capsule, capsule_name)
for i in range(n):
out[i] = bounded_uint(lb, ub, rng)
diff --git a/numpy/random/examples/cython/extending_distributions.pyx b/numpy/random/examples/cython/extending_distributions.pyx
index 26d749b10..da584e941 100644
--- a/numpy/random/examples/cython/extending_distributions.pyx
+++ b/numpy/random/examples/cython/extending_distributions.pyx
@@ -1,26 +1,28 @@
+#!/usr/bin/env python
#cython: language_level=3
+
import numpy as np
cimport numpy as np
cimport cython
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
-from numpy.random.randomgen.common cimport *
-from numpy.random.randomgen.distributions cimport random_gauss_zig
-from numpy.random.randomgen import Xoroshiro128
+from numpy.random.common cimport *
+from numpy.random.distributions cimport random_gauss_zig
+from numpy.random import Xoroshiro128
@cython.boundscheck(False)
@cython.wraparound(False)
def normals_zig(Py_ssize_t n):
cdef Py_ssize_t i
- cdef brng_t *rng
- cdef const char *capsule_name = "BasicRNG"
+ cdef bitgen_t *rng
+ cdef const char *capsule_name = "BitGenerator"
cdef double[::1] random_values
x = Xoroshiro128()
capsule = x.capsule
if not PyCapsule_IsValid(capsule, capsule_name):
raise ValueError("Invalid pointer to anon_func_state")
- rng = <brng_t *> PyCapsule_GetPointer(capsule, capsule_name)
+ rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
random_values = np.empty(n)
for i in range(n):
random_values[i] = random_gauss_zig(rng)
@@ -32,17 +34,17 @@ def normals_zig(Py_ssize_t n):
@cython.wraparound(False)
def uniforms(Py_ssize_t n):
cdef Py_ssize_t i
- cdef brng_t *rng
- cdef const char *capsule_name = "BasicRNG"
+ cdef bitgen_t *rng
+ cdef const char *capsule_name = "BitGenerator"
cdef double[::1] random_values
x = Xoroshiro128()
capsule = x.capsule
- # Optional check that the capsule if from a Basic RNG
+ # Optional check that the capsule if from a BitGenerator
if not PyCapsule_IsValid(capsule, capsule_name):
raise ValueError("Invalid pointer to anon_func_state")
# Cast the pointer
- rng = <brng_t *> PyCapsule_GetPointer(capsule, capsule_name)
+ rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
random_values = np.empty(n)
for i in range(n):
# Call the function
diff --git a/numpy/random/examples/cython/setup.py b/numpy/random/examples/cython/setup.py
index d7a04f75a..69f057ed5 100644
--- a/numpy/random/examples/cython/setup.py
+++ b/numpy/random/examples/cython/setup.py
@@ -1,4 +1,10 @@
-# python setup.py build_ext -i
+#!/usr/bin/env python3
+"""
+Build the demos
+
+Usage: python setup.py build_ext -i
+"""
+
import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
@@ -10,7 +16,7 @@ extending = Extension("extending",
include_dirs=[np.get_include()])
distributions = Extension("extending_distributions",
sources=['extending_distributions.pyx',
- join('..', '..', '..', 'randomgen', 'src',
+ join('..', '..', 'src',
'distributions', 'distributions.c')],
include_dirs=[np.get_include()])
diff --git a/numpy/random/examples/numba/extending_distributions.py b/numpy/random/examples/numba/extending_distributions.py
index 17ba2704c..e1a57fa4f 100644
--- a/numpy/random/examples/numba/extending_distributions.py
+++ b/numpy/random/examples/numba/extending_distributions.py
@@ -35,26 +35,26 @@ else:
raise RuntimeError('Required DLL/so file was not found.')
ffi.cdef("""
-double random_gauss_zig(void *brng_state);
+double random_gauss_zig(void *bitgen_state);
""")
x = Xoroshiro128()
xffi = x.cffi
-brng = xffi.brng
+bit_generator = xffi.bitgen
random_gauss_zig = lib.random_gauss_zig
-def normals(n, brng):
+def normals(n, bit_generator):
out = np.empty(n)
for i in range(n):
- out[i] = random_gauss_zig(brng)
+ out[i] = random_gauss_zig(bit_generator)
return out
normalsj = nb.jit(normals, nopython=True)
# Numba requires a memory address for void *
-# Can also get address from x.ctypes.brng.value
-brng_address = int(ffi.cast('uintptr_t', brng))
+# Can also get address from x.ctypes.bit_generator.value
+bit_generator_address = int(ffi.cast('uintptr_t', bit_generator))
-norm = normalsj(1000, brng_address)
+norm = normalsj(1000, bit_generator_address)
diff --git a/numpy/random/generator.pyx b/numpy/random/generator.pyx
index 6910a1e48..6cba3c3c7 100644
--- a/numpy/random/generator.pyx
+++ b/numpy/random/generator.pyx
@@ -3,32 +3,34 @@
import operator
import warnings
+import numpy as np
+
+from .bounded_integers import _integers_types
+from .xoroshiro128 import Xoroshiro128
+
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
from cpython cimport (Py_INCREF, PyFloat_AsDouble)
from libc cimport string
-from libc.stdlib cimport malloc, free
-cimport numpy as np
-import numpy as np
+
cimport cython
+cimport numpy as np
from .bounded_integers cimport *
-from .bounded_integers import _randint_types
from .common cimport *
from .distributions cimport *
-from .xoroshiro128 import Xoroshiro128
np.import_array()
-cdef class RandomGenerator:
+cdef class Generator:
"""
- RandomGenerator(brng=None)
+ Generator(bit_generator=None)
- Container for the Basic Random Number Generators.
+ Container for the BitGenerators.
- ``RandomGenerator`` exposes a number of methods for generating random
- numbers drawn from a variety of probability distributions. In addition to the
- distribution-specific arguments, each method takes a keyword argument
+ ``Generator`` exposes a number of methods for generating random
+ numbers drawn from a variety of probability distributions. In addition to
+ the distribution-specific arguments, each method takes a keyword argument
`size` that defaults to ``None``. If `size` is ``None``, then a single
value is generated and returned. If `size` is an integer, then a 1-D
array filled with generated values is returned. If `size` is a tuple,
@@ -36,98 +38,106 @@ cdef class RandomGenerator:
**No Compatibility Guarantee**
- ``RandomGenerator`` is evolving and so it isn't possible to provide a
- compatibility guarantee like NumPy does. In particular, better algorithms
- have already been added. This will change once ``RandomGenerator``
- stabilizes.
+ ``Generator`` does not provide a version compatibility guarantee. In
+ particular, as better algorithms evolve the bit stream may change.
Parameters
----------
- brng : Basic RNG, optional
- Basic RNG to use as the core generator. If none is provided, uses
+ bit_generator : BitGenerator, optional
+ BitGenerator to use as the core generator. If none is provided, uses
Xoroshiro128.
Notes
-----
The Python stdlib module `random` contains pseudo-random number generator
with a number of methods that are similar to the ones available in
- ``RandomGenerator``. It uses Mersenne Twister, and this basic RNG can be
- accessed using ``MT19937``. ``RandomGenerator``, besides being
+ ``Generator``. It uses Mersenne Twister, and this bit generator can
+ be accessed using ``MT19937``. ``Generator``, besides being
NumPy-aware, has the advantage that it provides a much larger number
of probability distributions to choose from.
Examples
--------
- >>> from numpy.random import RandomGenerator
- >>> rg = RandomGenerator()
+ >>> from numpy.random import Generator
+ >>> rg = Generator()
>>> rg.standard_normal()
-0.203 # random
Using a specific generator
>>> from numpy.random import MT19937
- >>> rg = RandomGenerator(MT19937())
-
- The generator is also directly available from basic RNGs
-
- >>> rg = MT19937().generator
- >>> rg.standard_normal()
- -0.203 # random
+ >>> rg = Generator(MT19937())
"""
- cdef public object brng
- cdef brng_t *_brng
- cdef binomial_t *_binomial
+ cdef public object _bit_generator
+ cdef bitgen_t _bitgen
+ cdef binomial_t _binomial
cdef object lock
poisson_lam_max = POISSON_LAM_MAX
- def __init__(self, brng=None):
- if brng is None:
- brng = Xoroshiro128()
- self.brng = brng
+ def __init__(self, bit_generator=None):
+ if bit_generator is None:
+ bit_generator = Xoroshiro128()
+ self._bit_generator = bit_generator
- capsule = brng.capsule
- cdef const char *name = "BasicRNG"
+ capsule = bit_generator.capsule
+ cdef const char *name = "BitGenerator"
if not PyCapsule_IsValid(capsule, name):
- raise ValueError("Invalid brng. The brng must be instantized.")
- self._brng = <brng_t *> PyCapsule_GetPointer(capsule, name)
- self._binomial = <binomial_t *>malloc(sizeof(binomial_t))
- self.lock = brng.lock
-
- def __dealloc__(self):
- if self._binomial:
- free(self._binomial)
+ raise ValueError("Invalid bit generator'. The bit generator must "
+ "be instantiated.")
+ self._bitgen = (<bitgen_t *> PyCapsule_GetPointer(capsule, name))[0]
+ self.lock = bit_generator.lock
def __repr__(self):
return self.__str__() + ' at 0x{:X}'.format(id(self))
def __str__(self):
_str = self.__class__.__name__
- _str += '(' + self.brng.__class__.__name__ + ')'
+ _str += '(' + self.bit_generator.__class__.__name__ + ')'
return _str
# Pickling support:
def __getstate__(self):
- return self.brng.state
+ return self.bit_generator.state
def __setstate__(self, state):
- self.brng.state = state
+ self.bit_generator.state = state
def __reduce__(self):
from ._pickle import __generator_ctor
- return __generator_ctor, (self.brng.state['brng'],), self.brng.state
+ return __generator_ctor, (self.bit_generator.state['bit_generator'],), self.bit_generator.state
- def random_sample(self, size=None, dtype=np.float64, out=None):
+ @property
+ def bit_generator(self):
+ """
+ Gets the bit generator instance used by the generator
+
+ Returns
+ -------
+ bit_generator : BitGenerator
+ The bit generator instance used by the generator
"""
- random_sample(size=None, dtype='d', out=None)
+ return self._bit_generator
+
+ def random_sample(self, *args, **kwargs):
+ """
+ Deprecated, renamed to ``random``
+ """
+ warnings.warn("Renamed to random", RuntimeWarning)
+ self.random(*args, **kwargs)
+
+
+ def random(self, size=None, dtype=np.float64, out=None):
+ """
+ random(size=None, dtype='d', out=None)
Return random floats in the half-open interval [0.0, 1.0).
Results are from the "continuous uniform" distribution over the
stated interval. To sample :math:`Unif[a, b), b > a` multiply
- the output of `random_sample` by `(b-a)` and add `a`::
+ the output of `random` by `(b-a)` and add `a`::
- (b - a) * random_sample() + a
+ (b - a) * random() + a
Parameters
----------
@@ -152,16 +162,16 @@ cdef class RandomGenerator:
Examples
--------
- >>> np.random.gen.random_sample()
+ >>> np.random.Generator().random()
0.47108547995356098 # random
- >>> type(np.random.gen.random_sample())
+ >>> type(np.random.Generator().random())
<class 'float'>
- >>> np.random.gen.random_sample((5,))
+ >>> np.random.Generator().random((5,))
array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) # random
Three-by-two array of random numbers from [-5, 0):
- >>> 5 * np.random.gen.random_sample((3, 2)) - 5
+ >>> 5 * np.random.Generator().random((3, 2)) - 5
array([[-3.99149989, -0.52338984], # random
[-2.99091858, -0.79479508],
[-1.23204345, -1.75224494]])
@@ -170,11 +180,11 @@ cdef class RandomGenerator:
cdef double temp
key = np.dtype(dtype).name
if key == 'float64':
- return double_fill(&random_double_fill, self._brng, size, self.lock, out)
+ return double_fill(&random_double_fill, &self._bitgen, size, self.lock, out)
elif key == 'float32':
- return float_fill(&random_float, self._brng, size, self.lock, out)
+ return float_fill(&random_float, &self._bitgen, size, self.lock, out)
else:
- raise TypeError('Unsupported dtype "%s" for random_sample' % key)
+ raise TypeError('Unsupported dtype "%s" for random' % key)
def beta(self, a, b, size=None):
"""
@@ -214,7 +224,7 @@ cdef class RandomGenerator:
Drawn samples from the parameterized beta distribution.
"""
- return cont(&random_beta, self._brng, size, self.lock, 2,
+ return cont(&random_beta, &self._bitgen, size, self.lock, 2,
a, 'a', CONS_POSITIVE,
b, 'b', CONS_POSITIVE,
0.0, '', CONS_NONE, None)
@@ -265,7 +275,7 @@ cdef class RandomGenerator:
https://en.wikipedia.org/wiki/Exponential_distribution
"""
- return cont(&random_exponential, self._brng, size, self.lock, 1,
+ return cont(&random_exponential, &self._bitgen, size, self.lock, 1,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE,
@@ -307,20 +317,20 @@ cdef class RandomGenerator:
--------
Output a 3x8000 array:
- >>> n = np.random.gen.standard_exponential((3, 8000))
+ >>> n = np.random.Generator().standard_exponential((3, 8000))
"""
key = np.dtype(dtype).name
if key == 'float64':
if method == u'zig':
- return double_fill(&random_standard_exponential_zig_fill, self._brng, size, self.lock, out)
+ return double_fill(&random_standard_exponential_zig_fill, &self._bitgen, size, self.lock, out)
else:
- return double_fill(&random_standard_exponential_fill, self._brng, size, self.lock, out)
+ return double_fill(&random_standard_exponential_fill, &self._bitgen, size, self.lock, out)
elif key == 'float32':
if method == u'zig':
- return float_fill(&random_standard_exponential_zig_f, self._brng, size, self.lock, out)
+ return float_fill(&random_standard_exponential_zig_f, &self._bitgen, size, self.lock, out)
else:
- return float_fill(&random_standard_exponential_f, self._brng, size, self.lock, out)
+ return float_fill(&random_standard_exponential_f, &self._bitgen, size, self.lock, out)
else:
raise TypeError('Unsupported dtype "%s" for standard_exponential'
% key)
@@ -347,13 +357,11 @@ cdef class RandomGenerator:
See Also
--------
- randint : Uniform sampling over a given half-open interval of integers.
- random_integers : Uniform sampling over a given closed interval of
- integers.
+ integers : Uniform sampling over a given half-open interval of integers.
Examples
--------
- >>> rg = np.random.RandomGenerator() # need a RandomGenerator object
+ >>> rg = np.random.Generator() # need a Generator object
>>> rg.tomaxint((2,2,2))
array([[[1170048599, 1600360186], # random
[ 739731006, 1947757578]],
@@ -366,28 +374,26 @@ cdef class RandomGenerator:
[ True, True]]])
"""
- return self.randint(0, np.iinfo(np.int).max + 1, dtype=np.int, size=size)
+ return self.integers(0, np.iinfo(np.int).max + 1, dtype=np.int, size=size)
- def randint(self, low, high=None, size=None, dtype=np.int64, use_masked=True,
- closed=False):
+ def integers(self, low, high=None, size=None, dtype=np.int64, endpoint=False):
"""
- randint(low, high=None, size=None, dtype='int64', use_masked=True, closed=False)
+ integers(low, high=None, size=None, dtype='int64', endpoint=False)
Return random integers from `low` (inclusive) to `high` (exclusive), or
- if closed=True, `low` (inclusive) to `high` (inclusive).
+ if endpoint=True, `low` (inclusive) to `high` (inclusive). Replaces
+ randint (with endpoint=False) and random_integers (with endpoint=True)
Return random integers from the "discrete uniform" distribution of
- the specified dtype in the "half-open" interval [`low`, `high`). If
- `high` is None (the default), then results are from [0, `low`). If
- `closed` is True, then samples from the closed interval [`low`, `high`]
- or [0, `low`] if `high` is None.
+ the specified dtype. If `high` is None (the default), then results are
+ from 0 to `low`.
Parameters
----------
low : int or array-like of ints
Lowest (signed) integers to be drawn from the distribution (unless
- ``high=None``, in which case this parameter is one above the
- *highest* such integer).
+ ``high=None``, in which case this parameter is 0 and this value is
+ used for `high`).
high : int or array-like of ints, optional
If provided, one above the largest (signed) integer to be drawn
from the distribution (see above for behavior if ``high=None``).
@@ -404,16 +410,10 @@ cdef class RandomGenerator:
.. versionadded:: 1.11.0
- use_masked : bool
- If True the generator uses rejection sampling with a bit mask to
- reject random numbers that are out of bounds. If False the
- generator will use Lemire's rejection sampling algorithm.
-
- .. versionadded:: 1.15.1
-
- closed : bool
+ endpoint : bool, optional
If true, sample from the interval [low, high] instead of the
default [low, high)
+ Defaults to False
Returns
-------
@@ -427,38 +427,32 @@ cdef class RandomGenerator:
cannot be represented as a standard integer type. The high array (or
low if high is None) must have object dtype, e.g., array([2**64]).
- See Also
- --------
- random_integers : similar to `randint`, only for the closed interval
- [`low`, `high`], where 1 is the lowest value if
- `high` is omitted.
-
Examples
--------
- >>> np.random.gen.randint(2, size=10)
+ >>> np.random.Generator().integers(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random
- >>> np.random.gen.randint(1, size=10)
+ >>> np.random.Generator().integers(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Generate a 2 x 4 array of ints between 0 and 4, inclusive:
- >>> np.random.gen.randint(5, size=(2, 4))
+ >>> np.random.Generator().integers(5, size=(2, 4))
array([[4, 0, 2, 1],
[3, 2, 2, 0]]) # random
Generate a 1 x 3 array with 3 different upper bounds
- >>> np.random.gen.randint(1, [3, 5, 10])
+ >>> np.random.Generator().integers(1, [3, 5, 10])
array([2, 2, 9]) # random
Generate a 1 by 3 array with 3 different lower bounds
- >>> np.random.gen.randint([1, 5, 7], 10)
+ >>> np.random.Generator().integers([1, 5, 7], 10)
array([9, 8, 7]) # random
Generate a 2 by 4 array using broadcasting with dtype of uint8
- >>> np.random.gen.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
+ >>> np.random.Generator().integers([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
array([[ 8, 6, 9, 7],
[ 1, 16, 9, 12]], dtype=uint8) # random
@@ -473,27 +467,32 @@ cdef class RandomGenerator:
low = 0
key = np.dtype(dtype).name
- if key not in _randint_types:
- raise TypeError('Unsupported dtype "%s" for randint' % key)
+ if key not in _integers_types:
+ raise TypeError('Unsupported dtype "%s" for integers' % key)
+
+ # Implementation detail: the old API used a masked method to generate
+ # bounded uniform integers. Lemire's method is preferrable since it is
+ # faster. randomgen allows a choice, we will always use the faster one.
+ cdef bint _masked = True
if key == 'int32':
- ret = _rand_int32(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_int32(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'int64':
- ret = _rand_int64(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_int64(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'int16':
- ret = _rand_int16(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_int16(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'int8':
- ret = _rand_int8(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_int8(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'uint64':
- ret = _rand_uint64(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_uint64(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'uint32':
- ret = _rand_uint32(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_uint32(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'uint16':
- ret = _rand_uint16(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_uint16(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'uint8':
- ret = _rand_uint8(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_uint8(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
elif key == 'bool':
- ret = _rand_bool(low, high, size, use_masked, closed, self._brng, self.lock)
+ ret = _rand_bool(low, high, size, _masked, endpoint, &self._bitgen, self.lock)
if size is None and dtype in (np.bool, np.int, np.long):
if np.array(ret).shape == ():
@@ -518,12 +517,20 @@ cdef class RandomGenerator:
Examples
--------
- >>> np.random.gen.bytes(10)
+ >>> np.random.Generator().bytes(10)
' eh\\x85\\x022SZ\\xbf\\xa4' #random
"""
cdef Py_ssize_t n_uint32 = ((length - 1) // 4 + 1)
- return self.randint(0, 4294967296, size=n_uint32, dtype=np.uint32).tobytes()[:length]
+ return self.integers(0, 4294967296, size=n_uint32,
+ dtype=np.uint32).tobytes()[:length]
+
+ def randint(self, low, high=None, size=None, dtype=np.int64, endpoint=False):
+ """
+ Deprecated, renamed to ``integers``
+ """
+ warnings.warn("Renamed to integers", RuntimeWarning)
+ self.integers(low, high, size, dtype, endpoint)
@cython.wraparound(True)
def choice(self, a, size=None, replace=True, p=None, axis=0):
@@ -532,7 +539,7 @@ cdef class RandomGenerator:
Generates a random sample from a given 1-D array
- .. versionadded:: 1.7.0
+ .. versionadded:: 1.7.0
Parameters
----------
@@ -541,8 +548,11 @@ cdef class RandomGenerator:
If an int, the random sample is generated as if a were np.arange(a)
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
- ``m * n * k`` samples are drawn. Default is None, in which case a
- single value is returned.
+ ``m * n * k`` samples are drawn from the 1-d `a`. If `a` has more
+ than one dimension, the `size` shape will be inserted into the
+ `axis` dimension, so the output ``ndim`` will be ``a.ndim - 1 +
+ len(size)``. Default is None, in which case a single value is
+ returned.
replace : boolean, optional
Whether the sample is with or without replacement
p : 1-D array-like, optional
@@ -569,39 +579,39 @@ cdef class RandomGenerator:
See Also
--------
- randint, shuffle, permutation
+ integers, shuffle, permutation
Examples
--------
Generate a uniform random sample from np.arange(5) of size 3:
- >>> np.random.gen.choice(5, 3)
+ >>> np.random.Generator().choice(5, 3)
array([0, 3, 4]) # random
- >>> #This is equivalent to np.random.gen.randint(0,5,3)
+ >>> #This is equivalent to np.random.Generator().integers(0,5,3)
Generate a non-uniform random sample from np.arange(5) of size 3:
- >>> np.random.gen.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0])
+ >>> np.random.Generator().choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0])
array([3, 3, 0]) # random
Generate a uniform random sample from np.arange(5) of size 3 without
replacement:
- >>> np.random.gen.choice(5, 3, replace=False)
+ >>> np.random.Generator().choice(5, 3, replace=False)
array([3,1,0]) # random
- >>> #This is equivalent to np.random.gen.permutation(np.arange(5))[:3]
+ >>> #This is equivalent to np.random.Generator().permutation(np.arange(5))[:3]
Generate a non-uniform random sample from np.arange(5) of size
3 without replacement:
- >>> np.random.gen.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0])
+ >>> np.random.Generator().choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0])
array([2, 3, 0]) # random
Any of the above can be repeated with an arbitrary array-like
instead of just integers. For instance:
>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
- >>> np.random.gen.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
+ >>> np.random.Generator().choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], # random
dtype='<U11')
@@ -663,11 +673,11 @@ cdef class RandomGenerator:
if p is not None:
cdf = p.cumsum()
cdf /= cdf[-1]
- uniform_samples = self.random_sample(shape)
+ uniform_samples = self.random(shape)
idx = cdf.searchsorted(uniform_samples, side='right')
idx = np.array(idx, copy=False, dtype=np.int64) # searchsorted returns a scalar
else:
- idx = self.randint(0, pop_size, size=shape, dtype=np.int64)
+ idx = self.integers(0, pop_size, size=shape, dtype=np.int64)
else:
if size > pop_size:
raise ValueError("Cannot take a larger sample than "
@@ -683,7 +693,7 @@ cdef class RandomGenerator:
found = np.zeros(shape, dtype=np.int64)
flat_found = found.ravel()
while n_uniq < size:
- x = self.rand(size - n_uniq)
+ x = self.random((size - n_uniq,))
if n_uniq > 0:
p[flat_found[0:n_uniq]] = 0
cdf = np.cumsum(p)
@@ -718,7 +728,7 @@ cdef class RandomGenerator:
# Sample indices with one pass to avoid reacquiring the lock
with self.lock:
for j in range(pop_size_i - size_i, pop_size_i):
- idx_data[loc] = random_interval(self._brng, j)
+ idx_data[loc] = random_interval(&self._bitgen, j)
loc += 1
loc = 0
while len(idx_set) < size_i:
@@ -786,14 +796,9 @@ cdef class RandomGenerator:
See Also
--------
- randint : Discrete uniform distribution, yielding integers.
- random_integers : Discrete uniform distribution over the closed
- interval ``[low, high]``.
- random_sample : Floats uniformly distributed over ``[0, 1)``.
- random : Alias for `random_sample`.
- rand : Convenience function that accepts dimensions as input, e.g.,
- ``rand(2,2)`` would generate a 2-by-2 array of floats,
- uniformly distributed over ``[0, 1)``.
+ integers : Discrete uniform distribution, yielding integers.
+ random : Floats uniformly distributed over ``[0, 1)``.
+ random : Alias for `random`.
Notes
-----
@@ -813,7 +818,7 @@ cdef class RandomGenerator:
--------
Draw samples from the distribution:
- >>> s = np.random.gen.uniform(-1,0,1000)
+ >>> s = np.random.Generator().uniform(-1,0,1000)
All values are within the given interval:
@@ -846,7 +851,7 @@ cdef class RandomGenerator:
if not np.isfinite(range):
raise OverflowError('Range exceeds valid bounds')
- return cont(&random_uniform, self._brng, size, self.lock, 2,
+ return cont(&random_uniform, &self._bitgen, size, self.lock, 2,
_low, '', CONS_NONE,
range, '', CONS_NONE,
0.0, '', CONS_NONE,
@@ -860,218 +865,12 @@ cdef class RandomGenerator:
arange = <np.ndarray>np.PyArray_EnsureArray(temp)
if not np.all(np.isfinite(arange)):
raise OverflowError('Range exceeds valid bounds')
- return cont(&random_uniform, self._brng, size, self.lock, 2,
+ return cont(&random_uniform, &self._bitgen, size, self.lock, 2,
alow, '', CONS_NONE,
arange, '', CONS_NONE,
0.0, '', CONS_NONE,
None)
- def rand(self, *args, dtype=np.float64):
- """
- rand(d0, d1, ..., dn, dtype='d')
-
- Random values in a given shape.
-
- .. note::
- This is a convenience function for users porting code from Matlab,
- and wraps `numpy.random.gen.random_sample`. That function takes a
- tuple to specify the size of the output, which is consistent with
- other NumPy functions like `numpy.zeros` and `numpy.ones`.
-
- Create an array of the given shape and populate it with
- random samples from a uniform distribution
- over ``[0, 1)``.
-
- Parameters
- ----------
- d0, d1, ..., dn : int, optional
- The dimensions of the returned array, must be non-negative.
- If no argument is given a single Python float is returned.
- dtype : {str, dtype}, optional
- Desired dtype of the result, either 'd' (or 'float64') or 'f'
- (or 'float32'). All dtypes are determined by their name. The
- default value is 'd'.
-
- Returns
- -------
- out : ndarray, shape ``(d0, d1, ..., dn)``
- Random values.
-
- See Also
- --------
- random
-
- Examples
- --------
- >>> np.random.gen.rand(3,2)
- array([[ 0.14022471, 0.96360618], #random
- [ 0.37601032, 0.25528411], #random
- [ 0.49313049, 0.94909878]]) #random
-
- """
- if len(args) == 0:
- return self.random_sample(dtype=dtype)
- else:
- return self.random_sample(size=args, dtype=dtype)
-
- def randn(self, *args, dtype=np.float64):
- """
- randn(d0, d1, ..., dn, dtype='d')
-
- Return a sample (or samples) from the "standard normal" distribution.
-
- .. note::
- This is a convenience function for users porting code from Matlab,
- and wraps `numpy.random.gen.standard_normal`. That function takes a
- tuple to specify the size of the output, which is consistent with
- other NumPy functions like `numpy.zeros` and `numpy.ones`.
-
- If positive int_like arguments are provided, `randn` generates an array
- of shape ``(d0, d1, ..., dn)``, filled
- with random floats sampled from a univariate "normal" (Gaussian)
- distribution of mean 0 and variance 1. A single float randomly sampled
- from the distribution is returned if no argument is provided.
-
- Parameters
- ----------
- d0, d1, ..., dn : int, optional
- The dimensions of the returned array, must be non-negative.
- If no argument is given a single Python float is returned.
- dtype : {str, dtype}, optional
- Desired dtype of the result, either 'd' (or 'float64') or 'f'
- (or 'float32'). All dtypes are determined by their name. The
- default value is 'd'.
-
- Returns
- -------
- Z : ndarray or float
- A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from
- the standard normal distribution, or a single such float if
- no parameters were supplied.
-
- See Also
- --------
- standard_normal : Similar, but takes a tuple as its argument.
- normal : Also accepts mu and sigma arguments.
-
- Notes
- -----
- For random samples from :math:`N(\\mu, \\sigma^2)`, use:
-
- ``sigma * np.random.gen.randn(...) + mu``
-
- Examples
- --------
- >>> np.random.gen.randn()
- 2.1923875335537315 # random
-
- Two-by-four array of samples from N(3, 6.25):
-
- >>> 3 + 2.5 * np.random.gen.randn(2, 4)
- array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random
- [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
-
- """
- if len(args) == 0:
- return self.standard_normal(dtype=dtype)
- else:
- return self.standard_normal(size=args, dtype=dtype)
-
- def random_integers(self, low, high=None, size=None):
- """
- random_integers(low, high=None, size=None)
-
- Random integers of type np.int between `low` and `high`, inclusive.
-
- Return random integers of type np.int from the "discrete uniform"
- distribution in the closed interval [`low`, `high`]. If `high` is
- None (the default), then results are from [1, `low`]. The np.int
- type translates to the C long integer type and its precision
- is platform dependent.
-
- This function has been deprecated. Use randint instead.
-
- .. deprecated:: 1.11.0
-
- Parameters
- ----------
- low : int
- Lowest (signed) integer to be drawn from the distribution (unless
- ``high=None``, in which case this parameter is the *highest* such
- integer).
- high : int, optional
- If provided, the largest (signed) integer to be drawn from the
- distribution (see above for behavior if ``high=None``).
- size : int or tuple of ints, optional
- Output shape. If the given shape is, e.g., ``(m, n, k)``, then
- ``m * n * k`` samples are drawn. Default is None, in which case a
- single value is returned.
-
- Returns
- -------
- out : int or ndarray of ints
- `size`-shaped array of random integers from the appropriate
- distribution, or a single such random int if `size` not provided.
-
- See Also
- --------
- randint : Similar to `random_integers`, only for the half-open
- interval [`low`, `high`), and 0 is the lowest value if `high` is
- omitted.
-
- Notes
- -----
- To sample from N evenly spaced floating-point numbers between a and b,
- use::
-
- a + (b - a) * (np.random.gen.random_integers(N) - 1) / (N - 1.)
-
- Examples
- --------
- >>> np.random.gen.random_integers(5)
- 4 # random
- >>> type(np.random.gen.random_integers(5))
- <class 'numpy.int64'>
- >>> np.random.gen.random_integers(5, size=(3,2))
- array([[5, 4], # random
- [3, 3],
- [4, 5]])
-
- Choose five random numbers from the set of five evenly-spaced
- numbers between 0 and 2.5, inclusive (*i.e.*, from the set
- :math:`{0, 5/8, 10/8, 15/8, 20/8}`):
-
- >>> 2.5 * (np.random.gen.random_integers(5, size=(5,)) - 1) / 4.
- array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ]) # random
-
- Roll two six sided dice 1000 times and sum the results:
-
- >>> d1 = np.random.gen.random_integers(1, 6, 1000)
- >>> d2 = np.random.gen.random_integers(1, 6, 1000)
- >>> dsums = d1 + d2
-
- Display results as a histogram:
-
- >>> import matplotlib.pyplot as plt
- >>> count, bins, ignored = plt.hist(dsums, 11, density=True)
- >>> plt.show()
-
- """
- if high is None:
- warnings.warn(("This function is deprecated. Please call "
- "randint(1, {low} + 1) instead".format(low=low)),
- DeprecationWarning)
- high = low
- low = 1
-
- else:
- warnings.warn(("This function is deprecated. Please call "
- "randint({low}, {high} + 1)"
- "instead".format(low=low, high=high)),
- DeprecationWarning)
-
- return self.randint(low, high + 1, size=size, dtype='l')
-
# Complicated, continuous distributions:
def standard_normal(self, size=None, dtype=np.float64, out=None):
"""
@@ -1104,8 +903,8 @@ cdef class RandomGenerator:
-----
For random samples from :math:`N(\\mu, \\sigma^2)`, use one of::
- mu + sigma * np.random.gen.standard_normal(size=...)
- np.random.gen.normal(mu, sigma, size=...)
+ mu + sigma * np.random.Generator().standard_normal(size=...)
+ np.random.Generator().normal(mu, sigma, size=...)
See Also
--------
@@ -1115,31 +914,31 @@ cdef class RandomGenerator:
Examples
--------
- >>> np.random.gen.standard_normal()
+ >>> np.random.Generator().standard_normal()
2.1923875335537315 #random
- >>> s = np.random.gen.standard_normal(8000)
+ >>> s = np.random.Generator().standard_normal(8000)
>>> s
array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, # random
-0.38672696, -0.4685006 ]) # random
>>> s.shape
(8000,)
- >>> s = np.random.gen.standard_normal(size=(3, 4, 2))
+ >>> s = np.random.Generator().standard_normal(size=(3, 4, 2))
>>> s.shape
(3, 4, 2)
Two-by-four array of samples from :math:`N(3, 6.25)`:
- >>> 3 + 2.5 * np.random.gen.standard_normal(size=(2, 4))
+ >>> 3 + 2.5 * np.random.Generator().standard_normal(size=(2, 4))
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
"""
key = np.dtype(dtype).name
if key == 'float64':
- return double_fill(&random_gauss_zig_fill, self._brng, size, self.lock, out)
+ return double_fill(&random_gauss_zig_fill, &self._bitgen, size, self.lock, out)
elif key == 'float32':
- return float_fill(&random_gauss_zig_f, self._brng, size, self.lock, out)
+ return float_fill(&random_gauss_zig_f, &self._bitgen, size, self.lock, out)
else:
raise TypeError('Unsupported dtype "%s" for standard_normal' % key)
@@ -1197,8 +996,8 @@ cdef class RandomGenerator:
The function has its peak at the mean, and its "spread" increases with
the standard deviation (the function reaches 0.607 times its maximum at
:math:`x + \\sigma` and :math:`x - \\sigma` [2]_). This implies that
- `numpy.random.gen.normal` is more likely to return samples lying close to
- the mean, rather than those far away.
+ `numpy.random.Generator().normal` is more likely to return
+ samples lying close to the mean, rather than those far away.
References
----------
@@ -1213,7 +1012,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> mu, sigma = 0, 0.1 # mean and standard deviation
- >>> s = np.random.gen.normal(mu, sigma, 1000)
+ >>> s = np.random.Generator().normal(mu, sigma, 1000)
Verify the mean and the variance:
@@ -1235,12 +1034,12 @@ cdef class RandomGenerator:
Two-by-four array of samples from N(3, 6.25):
- >>> np.random.gen.normal(3, 2.5, size=(2, 4))
+ >>> np.random.Generator().normal(3, 2.5, size=(2, 4))
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
"""
- return cont(&random_normal_zig, self._brng, size, self.lock, 2,
+ return cont(&random_normal_zig, &self._bitgen, size, self.lock, 2,
loc, '', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
@@ -1309,7 +1108,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> shape, scale = 2., 1. # mean and width
- >>> s = np.random.gen.standard_gamma(shape, 1000000)
+ >>> s = np.random.Generator().standard_gamma(shape, 1000000)
Display the histogram of the samples, along with
the probability density function:
@@ -1326,13 +1125,13 @@ cdef class RandomGenerator:
cdef void *func
key = np.dtype(dtype).name
if key == 'float64':
- return cont(&random_standard_gamma_zig, self._brng, size, self.lock, 1,
+ return cont(&random_standard_gamma_zig, &self._bitgen, size, self.lock, 1,
shape, 'shape', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE,
out)
if key == 'float32':
- return cont_f(&random_standard_gamma_zig_f, self._brng, size, self.lock,
+ return cont_f(&random_standard_gamma_zig_f, &self._bitgen, size, self.lock,
shape, 'shape', CONS_NON_NEGATIVE,
out)
else:
@@ -1397,7 +1196,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
- >>> s = np.random.gen.gamma(shape, scale, 1000)
+ >>> s = np.random.Generator().gamma(shape, scale, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -1411,7 +1210,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_gamma, self._brng, size, self.lock, 2,
+ return cont(&random_gamma, &self._bitgen, size, self.lock, 2,
shape, 'shape', CONS_NON_NEGATIVE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -1487,7 +1286,7 @@ cdef class RandomGenerator:
>>> dfnum = 1. # between group degrees of freedom
>>> dfden = 48. # within groups degrees of freedom
- >>> s = np.random.gen.f(dfnum, dfden, 1000)
+ >>> s = np.random.Generator().f(dfnum, dfden, 1000)
The lower bound for the top 1% of the samples is :
@@ -1499,7 +1298,7 @@ cdef class RandomGenerator:
level.
"""
- return cont(&random_f, self._brng, size, self.lock, 2,
+ return cont(&random_f, &self._bitgen, size, self.lock, 2,
dfnum, 'dfnum', CONS_POSITIVE,
dfden, 'dfden', CONS_POSITIVE,
0.0, '', CONS_NONE, None)
@@ -1566,9 +1365,9 @@ cdef class RandomGenerator:
>>> dfnum = 3 # between group deg of freedom
>>> dfden = 20 # within groups degrees of freedom
>>> nonc = 3.0
- >>> nc_vals = np.random.gen.noncentral_f(dfnum, dfden, nonc, 1000000)
+ >>> nc_vals = np.random.Generator().noncentral_f(dfnum, dfden, nonc, 1000000)
>>> NF = np.histogram(nc_vals, bins=50, density=True)
- >>> c_vals = np.random.gen.f(dfnum, dfden, 1000000)
+ >>> c_vals = np.random.Generator().f(dfnum, dfden, 1000000)
>>> F = np.histogram(c_vals, bins=50, density=True)
>>> import matplotlib.pyplot as plt
>>> plt.plot(F[1][1:], F[0])
@@ -1576,7 +1375,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_noncentral_f, self._brng, size, self.lock, 3,
+ return cont(&random_noncentral_f, &self._bitgen, size, self.lock, 3,
dfnum, 'dfnum', CONS_POSITIVE,
dfden, 'dfden', CONS_POSITIVE,
nonc, 'nonc', CONS_NON_NEGATIVE, None)
@@ -1640,11 +1439,11 @@ cdef class RandomGenerator:
Examples
--------
- >>> np.random.gen.chisquare(2,4)
+ >>> np.random.Generator().chisquare(2,4)
array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272]) # random
"""
- return cont(&random_chisquare, self._brng, size, self.lock, 1,
+ return cont(&random_chisquare, &self._bitgen, size, self.lock, 1,
df, 'df', CONS_POSITIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -1699,7 +1498,7 @@ cdef class RandomGenerator:
Draw values from the distribution and plot the histogram
>>> import matplotlib.pyplot as plt
- >>> values = plt.hist(np.random.gen.noncentral_chisquare(3, 20, 100000),
+ >>> values = plt.hist(np.random.Generator().noncentral_chisquare(3, 20, 100000),
... bins=200, density=True)
>>> plt.show()
@@ -1707,9 +1506,9 @@ cdef class RandomGenerator:
and compare to a chisquare.
>>> plt.figure()
- >>> values = plt.hist(np.random.gen.noncentral_chisquare(3, .0000001, 100000),
+ >>> values = plt.hist(np.random.Generator().noncentral_chisquare(3, .0000001, 100000),
... bins=np.arange(0., 25, .1), density=True)
- >>> values2 = plt.hist(np.random.gen.chisquare(3, 100000),
+ >>> values2 = plt.hist(np.random.Generator().chisquare(3, 100000),
... bins=np.arange(0., 25, .1), density=True)
>>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')
>>> plt.show()
@@ -1718,12 +1517,12 @@ cdef class RandomGenerator:
distribution.
>>> plt.figure()
- >>> values = plt.hist(np.random.gen.noncentral_chisquare(3, 20, 100000),
+ >>> values = plt.hist(np.random.Generator().noncentral_chisquare(3, 20, 100000),
... bins=200, density=True)
>>> plt.show()
"""
- return cont(&random_noncentral_chisquare, self._brng, size, self.lock, 2,
+ return cont(&random_noncentral_chisquare, &self._bitgen, size, self.lock, 2,
df, 'df', CONS_POSITIVE,
nonc, 'nonc', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -1784,13 +1583,13 @@ cdef class RandomGenerator:
Draw samples and plot the distribution:
>>> import matplotlib.pyplot as plt
- >>> s = np.random.gen.standard_cauchy(1000000)
+ >>> s = np.random.Generator().standard_cauchy(1000000)
>>> s = s[(s>-25) & (s<25)] # truncate distribution so it plots well
>>> plt.hist(s, bins=100)
>>> plt.show()
"""
- return cont(&random_standard_cauchy, self._brng, size, self.lock, 0,
+ return cont(&random_standard_cauchy, &self._bitgen, size, self.lock, 0,
0.0, '', CONS_NONE, 0.0, '', CONS_NONE, 0.0, '', CONS_NONE, None)
def standard_t(self, df, size=None):
@@ -1857,7 +1656,7 @@ cdef class RandomGenerator:
We have 10 degrees of freedom, so is the sample mean within 95% of the
recommended value?
- >>> s = np.random.gen.standard_t(10, size=100000)
+ >>> s = np.random.Generator().standard_t(10, size=100000)
>>> np.mean(intake)
6753.636363636364
>>> intake.std(ddof=1)
@@ -1881,7 +1680,7 @@ cdef class RandomGenerator:
probability of about 99% of being true.
"""
- return cont(&random_standard_t, self._brng, size, self.lock, 1,
+ return cont(&random_standard_t, &self._bitgen, size, self.lock, 1,
df, 'df', CONS_POSITIVE,
0, '', CONS_NONE,
0, '', CONS_NONE,
@@ -1951,7 +1750,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> mu, kappa = 0.0, 4.0 # mean and dispersion
- >>> s = np.random.gen.vonmises(mu, kappa, 1000)
+ >>> s = np.random.Generator().vonmises(mu, kappa, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -1965,7 +1764,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_vonmises, self._brng, size, self.lock, 2,
+ return cont(&random_vonmises, &self._bitgen, size, self.lock, 2,
mu, 'mu', CONS_NONE,
kappa, 'kappa', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2051,7 +1850,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> a, m = 3., 2. # shape and mode
- >>> s = (np.random.gen.pareto(a, 1000) + 1) * m
+ >>> s = (np.random.Generator().pareto(a, 1000) + 1) * m
Display the histogram of the samples, along with the probability
density function:
@@ -2063,7 +1862,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_pareto, self._brng, size, self.lock, 1,
+ return cont(&random_pareto, &self._bitgen, size, self.lock, 1,
a, 'a', CONS_POSITIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2144,7 +1943,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> a = 5. # shape
- >>> s = np.random.gen.weibull(a, 1000)
+ >>> s = np.random.Generator().weibull(a, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -2154,14 +1953,14 @@ cdef class RandomGenerator:
>>> def weib(x,n,a):
... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)
- >>> count, bins, ignored = plt.hist(np.random.gen.weibull(5.,1000))
+ >>> count, bins, ignored = plt.hist(np.random.Generator().weibull(5.,1000))
>>> x = np.arange(1,100.)/50.
>>> scale = count.max()/weib(x, 1., 5.).max()
>>> plt.plot(x, weib(x, 1., 5.)*scale)
>>> plt.show()
"""
- return cont(&random_weibull, self._brng, size, self.lock, 1,
+ return cont(&random_weibull, &self._bitgen, size, self.lock, 1,
a, 'a', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2224,7 +2023,7 @@ cdef class RandomGenerator:
>>> a = 5. # shape
>>> samples = 1000
- >>> s = np.random.gen.power(a, samples)
+ >>> s = np.random.Generator().power(a, samples)
Display the histogram of the samples, along with
the probability density function:
@@ -2240,20 +2039,20 @@ cdef class RandomGenerator:
Compare the power function distribution to the inverse of the Pareto.
>>> from scipy import stats # doctest: +SKIP
- >>> rvs = np.random.gen.power(5, 1000000)
- >>> rvsp = np.random.gen.pareto(5, 1000000)
+ >>> rvs = np.random.Generator().power(5, 1000000)
+ >>> rvsp = np.random.Generator().pareto(5, 1000000)
>>> xx = np.linspace(0,1,100)
>>> powpdf = stats.powerlaw.pdf(xx,5) # doctest: +SKIP
>>> plt.figure()
>>> plt.hist(rvs, bins=50, density=True)
>>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
- >>> plt.title('np.random.gen.power(5)')
+ >>> plt.title('np.random.Generator().power(5)')
>>> plt.figure()
>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
>>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
- >>> plt.title('inverse of 1 + np.random.gen.pareto(5)')
+ >>> plt.title('inverse of 1 + np.random.Generator().pareto(5)')
>>> plt.figure()
>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
@@ -2261,7 +2060,7 @@ cdef class RandomGenerator:
>>> plt.title('inverse of stats.pareto(5)')
"""
- return cont(&random_power, self._brng, size, self.lock, 1,
+ return cont(&random_power, &self._bitgen, size, self.lock, 1,
a, 'a', CONS_POSITIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2328,7 +2127,7 @@ cdef class RandomGenerator:
Draw samples from the distribution
>>> loc, scale = 0., 1.
- >>> s = np.random.gen.laplace(loc, scale, 1000)
+ >>> s = np.random.Generator().laplace(loc, scale, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -2346,7 +2145,7 @@ cdef class RandomGenerator:
>>> plt.plot(x,g)
"""
- return cont(&random_laplace, self._brng, size, self.lock, 2,
+ return cont(&random_laplace, &self._bitgen, size, self.lock, 2,
loc, 'loc', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2431,7 +2230,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> mu, beta = 0, 0.1 # location and scale
- >>> s = np.random.gen.gumbel(mu, beta, 1000)
+ >>> s = np.random.Generator().gumbel(mu, beta, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -2449,7 +2248,7 @@ cdef class RandomGenerator:
>>> means = []
>>> maxima = []
>>> for i in range(0,1000) :
- ... a = np.random.gen.normal(mu, beta, 1000)
+ ... a = np.random.Generator().normal(mu, beta, 1000)
... means.append(a.mean())
... maxima.append(a.max())
>>> count, bins, ignored = plt.hist(maxima, 30, density=True)
@@ -2464,7 +2263,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_gumbel, self._brng, size, self.lock, 2,
+ return cont(&random_gumbel, &self._bitgen, size, self.lock, 2,
loc, 'loc', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2531,7 +2330,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> loc, scale = 10, 1
- >>> s = np.random.gen.logistic(loc, scale, 10000)
+ >>> s = np.random.Generator().logistic(loc, scale, 10000)
>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, bins=50)
@@ -2544,7 +2343,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_logistic, self._brng, size, self.lock, 2,
+ return cont(&random_logistic, &self._bitgen, size, self.lock, 2,
loc, 'loc', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2614,7 +2413,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> mu, sigma = 3., 1. # mean and standard deviation
- >>> s = np.random.gen.lognormal(mu, sigma, 1000)
+ >>> s = np.random.Generator().lognormal(mu, sigma, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -2638,7 +2437,7 @@ cdef class RandomGenerator:
>>> # values, drawn from a normal distribution.
>>> b = []
>>> for i in range(1000):
- ... a = 10. + np.random.gen.standard_normal(100)
+ ... a = 10. + np.random.Generator().standard_normal(100)
... b.append(np.product(a))
>>> b = np.array(b) / np.min(b) # scale values to be positive
@@ -2654,7 +2453,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return cont(&random_lognormal, self._brng, size, self.lock, 2,
+ return cont(&random_lognormal, &self._bitgen, size, self.lock, 2,
mean, 'mean', CONS_NONE,
sigma, 'sigma', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2706,7 +2505,7 @@ cdef class RandomGenerator:
Draw values from the distribution and plot the histogram
>>> from matplotlib.pyplot import hist
- >>> values = hist(np.random.gen.rayleigh(3, 100000), bins=200, density=True)
+ >>> values = hist(np.random.Generator().rayleigh(3, 100000), bins=200, density=True)
Wave heights tend to follow a Rayleigh distribution. If the mean wave
height is 1 meter, what fraction of waves are likely to be larger than 3
@@ -2714,7 +2513,7 @@ cdef class RandomGenerator:
>>> meanvalue = 1
>>> modevalue = np.sqrt(2 / np.pi) * meanvalue
- >>> s = np.random.gen.rayleigh(modevalue, 1000000)
+ >>> s = np.random.Generator().rayleigh(modevalue, 1000000)
The percentage of waves larger than 3 meters is:
@@ -2722,7 +2521,7 @@ cdef class RandomGenerator:
0.087300000000000003 # random
"""
- return cont(&random_rayleigh, self._brng, size, self.lock, 1,
+ return cont(&random_rayleigh, &self._bitgen, size, self.lock, 1,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2786,11 +2585,11 @@ cdef class RandomGenerator:
Draw values from the distribution and plot the histogram:
>>> import matplotlib.pyplot as plt
- >>> h = plt.hist(np.random.gen.wald(3, 2, 100000), bins=200, density=True)
+ >>> h = plt.hist(np.random.Generator().wald(3, 2, 100000), bins=200, density=True)
>>> plt.show()
"""
- return cont(&random_wald, self._brng, size, self.lock, 2,
+ return cont(&random_wald, &self._bitgen, size, self.lock, 2,
mean, 'mean', CONS_POSITIVE,
scale, 'scale', CONS_POSITIVE,
0.0, '', CONS_NONE, None)
@@ -2853,7 +2652,7 @@ cdef class RandomGenerator:
Draw values from the distribution and plot the histogram:
>>> import matplotlib.pyplot as plt
- >>> h = plt.hist(np.random.gen.triangular(-3, 0, 8, 100000), bins=200,
+ >>> h = plt.hist(np.random.Generator().triangular(-3, 0, 8, 100000), bins=200,
... density=True)
>>> plt.show()
@@ -2877,7 +2676,7 @@ cdef class RandomGenerator:
raise ValueError("mode > right")
if fleft == fright:
raise ValueError("left == right")
- return cont(&random_triangular, self._brng, size, self.lock, 3,
+ return cont(&random_triangular, &self._bitgen, size, self.lock, 3,
fleft, '', CONS_NONE,
fmode, '', CONS_NONE,
fright, '', CONS_NONE, None)
@@ -2889,7 +2688,7 @@ cdef class RandomGenerator:
if np.any(np.equal(oleft, oright)):
raise ValueError("left == right")
- return cont_broadcast_3(&random_triangular, self._brng, size, self.lock,
+ return cont_broadcast_3(&random_triangular, &self._bitgen, size, self.lock,
oleft, '', CONS_NONE,
omode, '', CONS_NONE,
oright, '', CONS_NONE)
@@ -2966,7 +2765,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> n, p = 10, .5 # number of trials, probability of each trial
- >>> s = np.random.gen.binomial(n, p, 1000)
+ >>> s = np.random.Generator().binomial(n, p, 1000)
# result of flipping a coin 10 times, tested 1000 times.
A real world example. A company drills 9 wild-cat oil exploration
@@ -2976,7 +2775,7 @@ cdef class RandomGenerator:
Let's do 20,000 trials of the model, and count the number that
generate zero positive results.
- >>> sum(np.random.gen.binomial(9, 0.1, 20000) == 0)/20000.
+ >>> sum(np.random.Generator().binomial(9, 0.1, 20000) == 0)/20000.
# answer = 0.38885, or 38%.
"""
@@ -3012,7 +2811,7 @@ cdef class RandomGenerator:
for i in range(cnt):
_dp = (<double*>np.PyArray_MultiIter_DATA(it, 1))[0]
_in = (<int64_t*>np.PyArray_MultiIter_DATA(it, 2))[0]
- (<int64_t*>np.PyArray_MultiIter_DATA(it, 0))[0] = random_binomial(self._brng, _dp, _in, self._binomial)
+ (<int64_t*>np.PyArray_MultiIter_DATA(it, 0))[0] = random_binomial(&self._bitgen, _dp, _in, &self._binomial)
np.PyArray_MultiIter_NEXT(it)
@@ -3025,7 +2824,7 @@ cdef class RandomGenerator:
if size is None:
with self.lock:
- return random_binomial(self._brng, _dp, _in, self._binomial)
+ return random_binomial(&self._bitgen, _dp, _in, &self._binomial)
randoms = <np.ndarray>np.empty(size, np.int64)
cnt = np.PyArray_SIZE(randoms)
@@ -3033,8 +2832,8 @@ cdef class RandomGenerator:
with self.lock, nogil:
for i in range(cnt):
- randoms_data[i] = random_binomial(self._brng, _dp, _in,
- self._binomial)
+ randoms_data[i] = random_binomial(&self._bitgen, _dp, _in,
+ &self._binomial)
return randoms
@@ -3103,13 +2902,13 @@ cdef class RandomGenerator:
for each successive well, that is what is the probability of a
single success after drilling 5 wells, after 6 wells, etc.?
- >>> s = np.random.gen.negative_binomial(1, 0.1, 100000)
+ >>> s = np.random.Generator().negative_binomial(1, 0.1, 100000)
>>> for i in range(1, 11): # doctest: +SKIP
... probability = sum(s<i) / 100000.
... print(i, "wells drilled, probability of one success =", probability)
"""
- return disc(&random_negative_binomial, self._brng, size, self.lock, 2, 0,
+ return disc(&random_negative_binomial, &self._bitgen, size, self.lock, 2, 0,
n, 'n', CONS_POSITIVE_NOT_NAN,
p, 'p', CONS_BOUNDED_0_1,
0.0, '', CONS_NONE)
@@ -3167,7 +2966,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> import numpy as np
- >>> s = np.random.gen.poisson(5, 10000)
+ >>> s = np.random.Generator().poisson(5, 10000)
Display histogram of the sample:
@@ -3177,10 +2976,10 @@ cdef class RandomGenerator:
Draw each 100 values for lambda 100 and 500:
- >>> s = np.random.gen.poisson(lam=(100., 500.), size=(100, 2))
+ >>> s = np.random.Generator().poisson(lam=(100., 500.), size=(100, 2))
"""
- return disc(&random_poisson, self._brng, size, self.lock, 1, 0,
+ return disc(&random_poisson, &self._bitgen, size, self.lock, 1, 0,
lam, 'lam', CONS_POISSON,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3242,7 +3041,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> a = 2. # parameter
- >>> s = np.random.gen.zipf(a, 1000)
+ >>> s = np.random.Generator().zipf(a, 1000)
Display the histogram of the samples, along with
the probability density function:
@@ -3260,7 +3059,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return disc(&random_zipf, self._brng, size, self.lock, 1, 0,
+ return disc(&random_zipf, &self._bitgen, size, self.lock, 1, 0,
a, 'a', CONS_GT_1,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3303,7 +3102,7 @@ cdef class RandomGenerator:
Draw ten thousand values from the geometric distribution,
with the probability of an individual success equal to 0.35:
- >>> z = np.random.gen.geometric(p=0.35, size=10000)
+ >>> z = np.random.Generator().geometric(p=0.35, size=10000)
How many trials succeeded after a single run?
@@ -3311,7 +3110,7 @@ cdef class RandomGenerator:
0.34889999999999999 #random
"""
- return disc(&random_geometric, self._brng, size, self.lock, 1, 0,
+ return disc(&random_geometric, &self._bitgen, size, self.lock, 1, 0,
p, 'p', CONS_BOUNDED_GT_0_1,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3393,7 +3192,7 @@ cdef class RandomGenerator:
>>> ngood, nbad, nsamp = 100, 2, 10
# number of good, number of bad, and number of samples
- >>> s = np.random.gen.hypergeometric(ngood, nbad, nsamp, 1000)
+ >>> s = np.random.Generator().hypergeometric(ngood, nbad, nsamp, 1000)
>>> from matplotlib.pyplot import hist
>>> hist(s)
# note that it is very unlikely to grab both bad items
@@ -3402,7 +3201,7 @@ cdef class RandomGenerator:
If you pull 15 marbles at random, how likely is it that
12 or more of them are one color?
- >>> s = np.random.gen.hypergeometric(15, 15, 15, 100000)
+ >>> s = np.random.Generator().hypergeometric(15, 15, 15, 100000)
>>> sum(s>=12)/100000. + sum(s<=3)/100000.
# answer = 0.003 ... pretty unlikely!
@@ -3423,14 +3222,14 @@ cdef class RandomGenerator:
if lngood + lnbad < lnsample:
raise ValueError("ngood + nbad < nsample")
- return disc(&random_hypergeometric, self._brng, size, self.lock, 0, 3,
+ return disc(&random_hypergeometric, &self._bitgen, size, self.lock, 0, 3,
lngood, 'ngood', CONS_NON_NEGATIVE,
lnbad, 'nbad', CONS_NON_NEGATIVE,
lnsample, 'nsample', CONS_NON_NEGATIVE)
if np.any(np.less(np.add(ongood, onbad), onsample)):
raise ValueError("ngood + nbad < nsample")
- return discrete_broadcast_iii(&random_hypergeometric, self._brng, size, self.lock,
+ return discrete_broadcast_iii(&random_hypergeometric, &self._bitgen, size, self.lock,
ongood, 'ngood', CONS_NON_NEGATIVE,
onbad, 'nbad', CONS_NON_NEGATIVE,
onsample, 'nsample', CONS_NON_NEGATIVE)
@@ -3497,7 +3296,7 @@ cdef class RandomGenerator:
Draw samples from the distribution:
>>> a = .6
- >>> s = np.random.gen.logseries(a, 10000)
+ >>> s = np.random.Generator().logseries(a, 10000)
>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s)
@@ -3510,7 +3309,7 @@ cdef class RandomGenerator:
>>> plt.show()
"""
- return disc(&random_logseries, self._brng, size, self.lock, 1, 0,
+ return disc(&random_logseries, &self._bitgen, size, self.lock, 1, 0,
p, 'p', CONS_BOUNDED_0_1,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3587,7 +3386,7 @@ cdef class RandomGenerator:
Diagonal covariance means that points are oriented along x or y-axis:
>>> import matplotlib.pyplot as plt
- >>> x, y = np.random.gen.multivariate_normal(mean, cov, 5000).T
+ >>> x, y = np.random.Generator().multivariate_normal(mean, cov, 5000).T
>>> plt.plot(x, y, 'x')
>>> plt.axis('equal')
>>> plt.show()
@@ -3607,7 +3406,7 @@ cdef class RandomGenerator:
--------
>>> mean = (1, 2)
>>> cov = [[1, 0], [0, 1]]
- >>> x = np.random.gen.multivariate_normal(mean, cov, (3, 3))
+ >>> x = np.random.Generator().multivariate_normal(mean, cov, (3, 3))
>>> x.shape
(3, 3, 2)
@@ -3721,14 +3520,14 @@ cdef class RandomGenerator:
--------
Throw a dice 20 times:
- >>> np.random.gen.multinomial(20, [1/6.]*6, size=1)
+ >>> np.random.Generator().multinomial(20, [1/6.]*6, size=1)
array([[4, 1, 7, 5, 2, 1]]) # random
It landed 4 times on 1, once on 2, etc.
Now, throw the dice 20 times, and 20 times again:
- >>> np.random.gen.multinomial(20, [1/6.]*6, size=2)
+ >>> np.random.Generator().multinomial(20, [1/6.]*6, size=2)
array([[3, 4, 3, 3, 4, 3],
[2, 4, 3, 4, 0, 7]]) # random
@@ -3738,7 +3537,7 @@ cdef class RandomGenerator:
Now, do one experiment throwing the dice 10 time, and 10 times again,
and another throwing the dice 20 times, and 20 times again:
- >>> np.random.gen.multinomial([[10], [20]], [1/6.]*6, size=2)
+ >>> np.random.Generator().multinomial([[10], [20]], [1/6.]*6, size=2)
array([[[2, 4, 0, 1, 2, 1],
[1, 3, 0, 3, 1, 2]],
[[1, 4, 4, 4, 4, 3],
@@ -3749,7 +3548,7 @@ cdef class RandomGenerator:
A loaded die is more likely to land on number 6:
- >>> np.random.gen.multinomial(100, [1/7.]*5 + [2/7.])
+ >>> np.random.Generator().multinomial(100, [1/7.]*5 + [2/7.])
array([11, 16, 14, 17, 16, 26]) # random
The probability inputs should be normalized. As an implementation
@@ -3758,12 +3557,12 @@ cdef class RandomGenerator:
A biased coin which has twice as much weight on one side as on the
other should be sampled like so:
- >>> np.random.gen.multinomial(100, [1.0 / 3, 2.0 / 3]) # RIGHT
+ >>> np.random.Generator().multinomial(100, [1.0 / 3, 2.0 / 3]) # RIGHT
array([38, 62]) # random
not like:
- >>> np.random.gen.multinomial(100, [1.0, 2.0]) # WRONG
+ >>> np.random.Generator().multinomial(100, [1.0, 2.0]) # WRONG
Traceback (most recent call last):
ValueError: pvals < 0, pvals > 1 or pvals contains NaNs
@@ -3801,7 +3600,7 @@ cdef class RandomGenerator:
with self.lock, nogil:
for i in range(sz):
ni = (<int64_t*>np.PyArray_MultiIter_DATA(it, 0))[0]
- random_multinomial(self._brng, ni, &mnix[offset], pix, d, self._binomial)
+ random_multinomial(&self._bitgen, ni, &mnix[offset], pix, d, &self._binomial)
offset += d
np.PyArray_MultiIter_NEXT(it)
return multin
@@ -3823,7 +3622,7 @@ cdef class RandomGenerator:
offset = 0
with self.lock, nogil:
for i in range(sz // d):
- random_multinomial(self._brng, ni, &mnix[offset], pix, d, self._binomial)
+ random_multinomial(&self._bitgen, ni, &mnix[offset], pix, d, &self._binomial)
offset += d
return multin
@@ -3896,7 +3695,7 @@ cdef class RandomGenerator:
average length, but allowing some variation in the relative sizes of
the pieces.
- >>> s = np.random.gen.dirichlet((10, 5, 3), 20).transpose()
+ >>> s = np.random.Generator().dirichlet((10, 5, 3), 20).transpose()
>>> import matplotlib.pyplot as plt
>>> plt.barh(range(20), s[0])
@@ -3955,7 +3754,7 @@ cdef class RandomGenerator:
while i < totsize:
acc = 0.0
for j in range(k):
- val_data[i+j] = random_standard_gamma_zig(self._brng,
+ val_data[i+j] = random_standard_gamma_zig(&self._bitgen,
alpha_data[j])
acc = acc + val_data[i + j]
invacc = 1/acc
@@ -3988,14 +3787,14 @@ cdef class RandomGenerator:
Examples
--------
>>> arr = np.arange(10)
- >>> np.random.gen.shuffle(arr)
+ >>> np.random.Generator().shuffle(arr)
>>> arr
[1 7 5 2 9 4 3 6 0 8] # random
Multi-dimensional arrays are only shuffled along the first axis:
>>> arr = np.arange(9).reshape((3, 3))
- >>> np.random.gen.shuffle(arr)
+ >>> np.random.Generator().shuffle(arr)
>>> arr
array([[3, 4, 5], # random
[6, 7, 8],
@@ -4032,7 +3831,7 @@ cdef class RandomGenerator:
buf = np.empty_like(x[0, ...])
with self.lock:
for i in reversed(range(1, n)):
- j = random_interval(self._brng, i)
+ j = random_interval(&self._bitgen, i)
if i == j:
# i == j is not needed and memcpy is undefined.
continue
@@ -4043,7 +3842,7 @@ cdef class RandomGenerator:
# Untyped path.
with self.lock:
for i in reversed(range(1, n)):
- j = random_interval(self._brng, i)
+ j = random_interval(&self._bitgen, i)
x[i], x[j] = x[j], x[i]
cdef inline _shuffle_raw(self, np.npy_intp n, np.npy_intp first,
@@ -4053,13 +3852,13 @@ cdef class RandomGenerator:
Parameters
----------
n
- Number of elements in data
+ Number of elements in data
first
- First observation to shuffle. Shuffles n-1,
+ First observation to shuffle. Shuffles n-1,
n-2, ..., first, so that when first=1 the entire
- array is shuffled
+ array is shuffled
itemsize
- Size in bytes of item
+ Size in bytes of item
stride
Array stride
data
@@ -4069,7 +3868,7 @@ cdef class RandomGenerator:
"""
cdef np.npy_intp i, j
for i in reversed(range(first, n)):
- j = random_interval(self._brng, i)
+ j = random_interval(&self._bitgen, i)
string.memcpy(buf, data + j * stride, itemsize)
string.memcpy(data + j * stride, data + i * stride, itemsize)
string.memcpy(data + i * stride, buf, itemsize)
@@ -4097,14 +3896,14 @@ cdef class RandomGenerator:
Examples
--------
- >>> np.random.gen.permutation(10)
+ >>> np.random.Generator().permutation(10)
array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random
- >>> np.random.gen.permutation([1, 4, 9, 12, 15])
+ >>> np.random.Generator().permutation([1, 4, 9, 12, 15])
array([15, 1, 9, 4, 12]) # random
>>> arr = np.arange(9).reshape((3, 3))
- >>> np.random.gen.permutation(arr)
+ >>> np.random.Generator().permutation(arr)
array([[6, 7, 8], # random
[0, 1, 2],
[3, 4, 5]])
@@ -4130,7 +3929,7 @@ cdef class RandomGenerator:
self.shuffle(idx)
return arr[idx]
-_random_generator = RandomGenerator()
+_random_generator = Generator()
beta = _random_generator.beta
binomial = _random_generator.binomial
@@ -4144,6 +3943,7 @@ gamma = _random_generator.gamma
geometric = _random_generator.geometric
gumbel = _random_generator.gumbel
hypergeometric = _random_generator.hypergeometric
+integers = _random_generator.integers
laplace = _random_generator.laplace
logistic = _random_generator.logistic
lognormal = _random_generator.lognormal
@@ -4158,11 +3958,7 @@ pareto = _random_generator.pareto
permutation = _random_generator.permutation
poisson = _random_generator.poisson
power = _random_generator.power
-rand = _random_generator.rand
-randint = _random_generator.randint
-randn = _random_generator.randn
-random_integers = _random_generator.random_integers
-random_sample = _random_generator.random_sample
+random = _random_generator.random
rayleigh = _random_generator.rayleigh
shuffle = _random_generator.shuffle
standard_cauchy = _random_generator.standard_cauchy
@@ -4177,3 +3973,4 @@ vonmises = _random_generator.vonmises
wald = _random_generator.wald
weibull = _random_generator.weibull
zipf = _random_generator.zipf
+
diff --git a/numpy/random/legacy_distributions.pxd b/numpy/random/legacy_distributions.pxd
index 69e5d69be..7969cfb92 100644
--- a/numpy/random/legacy_distributions.pxd
+++ b/numpy/random/legacy_distributions.pxd
@@ -1,42 +1,42 @@
#cython: language_level=3
-from libc.stdint cimport uint64_t
+from libc.stdint cimport int64_t
import numpy as np
cimport numpy as np
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
cdef extern from "distributions-boxmuller.h":
- struct aug_brng:
- brng_t *basicrng
+ struct aug_bitgen:
+ bitgen_t *bit_generator
int has_gauss
double gauss
- ctypedef aug_brng aug_brng_t
-
- double legacy_gauss(aug_brng_t *aug_state) nogil
- double legacy_pareto(aug_brng_t *aug_state, double a) nogil
- double legacy_weibull(aug_brng_t *aug_state, double a) nogil
- double legacy_standard_gamma(aug_brng_t *aug_state, double shape) nogil
- double legacy_normal(aug_brng_t *aug_state, double loc, double scale) nogil
- double legacy_standard_t(aug_brng_t *aug_state, double df) nogil
-
- double legacy_standard_exponential(aug_brng_t *aug_state) nogil
- double legacy_power(aug_brng_t *aug_state, double a) nogil
- double legacy_gamma(aug_brng_t *aug_state, double shape, double scale) nogil
- double legacy_power(aug_brng_t *aug_state, double a) nogil
- double legacy_chisquare(aug_brng_t *aug_state, double df) nogil
- double legacy_noncentral_chisquare(aug_brng_t *aug_state, double df,
+ ctypedef aug_bitgen aug_bitgen_t
+
+ double legacy_gauss(aug_bitgen_t *aug_state) nogil
+ double legacy_pareto(aug_bitgen_t *aug_state, double a) nogil
+ double legacy_weibull(aug_bitgen_t *aug_state, double a) nogil
+ double legacy_standard_gamma(aug_bitgen_t *aug_state, double shape) nogil
+ double legacy_normal(aug_bitgen_t *aug_state, double loc, double scale) nogil
+ double legacy_standard_t(aug_bitgen_t *aug_state, double df) nogil
+
+ double legacy_standard_exponential(aug_bitgen_t *aug_state) nogil
+ double legacy_power(aug_bitgen_t *aug_state, double a) nogil
+ double legacy_gamma(aug_bitgen_t *aug_state, double shape, double scale) nogil
+ double legacy_power(aug_bitgen_t *aug_state, double a) nogil
+ double legacy_chisquare(aug_bitgen_t *aug_state, double df) nogil
+ double legacy_noncentral_chisquare(aug_bitgen_t *aug_state, double df,
double nonc) nogil
- double legacy_noncentral_f(aug_brng_t *aug_state, double dfnum, double dfden,
+ double legacy_noncentral_f(aug_bitgen_t *aug_state, double dfnum, double dfden,
double nonc) nogil
- double legacy_wald(aug_brng_t *aug_state, double mean, double scale) nogil
- double legacy_lognormal(aug_brng_t *aug_state, double mean, double sigma) nogil
- uint64_t legacy_negative_binomial(aug_brng_t *aug_state, double n, double p) nogil
- double legacy_standard_cauchy(aug_brng_t *state) nogil
- double legacy_beta(aug_brng_t *aug_state, double a, double b) nogil
- double legacy_f(aug_brng_t *aug_state, double dfnum, double dfden) nogil
- double legacy_exponential(aug_brng_t *aug_state, double scale) nogil
- double legacy_power(aug_brng_t *state, double a) nogil
+ double legacy_wald(aug_bitgen_t *aug_state, double mean, double scale) nogil
+ double legacy_lognormal(aug_bitgen_t *aug_state, double mean, double sigma) nogil
+ int64_t legacy_negative_binomial(aug_bitgen_t *aug_state, double n, double p) nogil
+ double legacy_standard_cauchy(aug_bitgen_t *state) nogil
+ double legacy_beta(aug_bitgen_t *aug_state, double a, double b) nogil
+ double legacy_f(aug_bitgen_t *aug_state, double dfnum, double dfden) nogil
+ double legacy_exponential(aug_bitgen_t *aug_state, double scale) nogil
+ double legacy_power(aug_bitgen_t *state, double a) nogil
diff --git a/numpy/random/mt19937.pyx b/numpy/random/mt19937.pyx
index 8ed229984..0579b3634 100644
--- a/numpy/random/mt19937.pyx
+++ b/numpy/random/mt19937.pyx
@@ -1,6 +1,5 @@
import operator
-from libc.stdlib cimport malloc, free
from cpython.pycapsule cimport PyCapsule_New
try:
@@ -12,7 +11,7 @@ import numpy as np
cimport numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy
np.import_array()
@@ -55,24 +54,26 @@ cdef class MT19937:
seed : {None, int, array_like}, optional
Random seed used to initialize the pseudo-random number generator. Can
be any integer between 0 and 2**32 - 1 inclusive, an array (or other
- sequence) of such integers, or ``None`` (the default). If `seed` is
- ``None``, then will attempt to read data from ``/dev/urandom``
- (or the Windows analog) if available or seed from the clock otherwise.
+ sequence) of unsigned 32-bit integers, or ``None`` (the default). If
+ `seed` is ``None``, a 32-bit unsigned integer is read from
+ ``/dev/urandom`` (or the Windows analog) if available. If unavailable,
+ a 32-bit hash of the time and process ID is used.
Notes
-----
- ``MT19937`` directly provides generators for doubles, and unsigned 32 and 64-
- bit integers [1]_ . These are not directly available and must be consumed
- via a ``RandomGenerator`` object.
+ ``MT19937`` provides a capsule containing function pointers that produce
+ doubles, and unsigned 32 and 64- bit integers [1]_. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
The Python stdlib module "random" also contains a Mersenne Twister
pseudo-random number generator.
**State and Seeding**
- The ``MT19937`` state vector consists of a 768 element array of
+ The ``MT19937`` state vector consists of a 768-element array of
32-bit unsigned integers plus a single integer value between 0 and 768
- indicating the current position within the main array.
+ that indexes the current position within the main array.
``MT19937`` is seeded using either a single 32-bit unsigned integer
or a vector of 32-bit unsigned integers. In either case, the input seed is
@@ -81,30 +82,29 @@ cdef class MT19937:
for the seed can only initialize a small range of the possible initial
state values.
- **Compatibility Guarantee**
-
- ``MT19937`` make a compatibility guarantee. A fixed seed and a fixed
- series of calls to ``MT19937`` methods will always produce the same
- results up to roundoff error except when the values were incorrect.
- Incorrect values will be fixed and the version in which the fix was
- made will be noted in the relevant docstring.
-
**Parallel Features**
``MT19937`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if :math:`2^{128}`
- random numbers have been generated ([1]_, [2]_). This allows the original sequence to
- be split so that distinct segments can be used in each worker process. All
- generators should be initialized with the same seed to ensure that the
- segments come from the same sequence.
+ calling the method ``jumped`` which advances the state as-if
+ :math:`2^{128}` random numbers have been generated ([1]_, [2]_). This
+ allows the original sequence to be split so that distinct segments can be
+ used in each worker process. All generators should be chained to ensure
+ that the segments come from the same sequence.
>>> from numpy.random.entropy import random_entropy
- >>> from numpy.random import RandomGenerator, MT19937
+ >>> from numpy.random import Generator, MT19937
>>> seed = random_entropy()
- >>> rs = [RandomGenerator(MT19937(seed)) for _ in range(10)]
- # Advance each MT19937 instance by i jumps
- >>> for i in range(10):
- ... rs[i].brng.jump(i)
+ >>> bit_generator = MT19937(seed)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
+
+ **Compatibility Guarantee**
+
+ ``MT19937`` makes a guarantee that a fixed seed and will always produce
+ the same random integer stream.
References
----------
@@ -117,38 +117,28 @@ cdef class MT19937:
No. 3, Summer 2008, pp. 385-390.
"""
- cdef mt19937_state *rng_state
- cdef brng_t *_brng
+ cdef mt19937_state rng_state
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None):
- self.rng_state = <mt19937_state *>malloc(sizeof(mt19937_state))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
self.seed(seed)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &mt19937_uint64
- self._brng.next_uint32 = &mt19937_uint32
- self._brng.next_double = &mt19937_double
- self._brng.next_raw = &mt19937_raw
+ self._bitgen.state = &self.rng_state
+ self._bitgen.next_uint64 = &mt19937_uint64
+ self._bitgen.next_uint32 = &mt19937_uint32
+ self._bitgen.next_double = &mt19937_double
+ self._bitgen.next_raw = &mt19937_raw
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ cdef const char *name = "BitGenerator"
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -158,16 +148,14 @@ cdef class MT19937:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
def random_raw(self, size=None, output=True):
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -192,10 +180,10 @@ cdef class MT19937:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None):
"""
@@ -226,14 +214,14 @@ cdef class MT19937:
seed = random_entropy(1)
except RuntimeError:
seed = random_entropy(1, 'fallback')
- mt19937_seed(self.rng_state, seed[0])
+ mt19937_seed(&self.rng_state, seed[0])
else:
if hasattr(seed, 'squeeze'):
seed = seed.squeeze()
idx = operator.index(seed)
if idx > int(2**32 - 1) or idx < 0:
raise ValueError("Seed must be between 0 and 2**32 - 1")
- mt19937_seed(self.rng_state, seed)
+ mt19937_seed(&self.rng_state, seed)
except TypeError:
obj = np.asarray(seed)
if obj.size == 0:
@@ -244,28 +232,50 @@ cdef class MT19937:
if ((obj > int(2**32 - 1)) | (obj < 0)).any():
raise ValueError("Seed must be between 0 and 2**32 - 1")
obj = obj.astype(np.uint32, casting='unsafe', order='C')
- mt19937_init_by_array(self.rng_state, <uint32_t*> obj.data, np.PyArray_DIM(obj, 0))
+ mt19937_init_by_array(&self.rng_state, <uint32_t*> obj.data, np.PyArray_DIM(obj, 0))
+
+ cdef jump_inplace(self, iter):
+ """
+ Jump state in-place
+
+ Not part of public API
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the rng.
+ """
+ cdef np.npy_intp i
+ for i in range(iter):
+ mt19937_jump(&self.rng_state)
- def jump(self, np.npy_intp iter=1):
+
+ def jumped(self, np.npy_intp iter=1):
"""
- jump(iter=1)
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
- Jumps the state as-if 2**128 random numbers have been generated.
+ The state of the returned big generator is jumped as-if
+ 2**(128 * iter) random numbers have been generated.
Parameters
----------
iter : integer, positive
- Number of times to jump the state of the brng.
+ Number of times to jump the state of the bit generator returned
Returns
-------
- self : DSFMT
- PRNG jumped iter times
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
"""
- cdef np.npy_intp i
- for i in range(iter):
- mt19937_jump(self.rng_state)
- return self
+ cdef MT19937 bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
@property
def state(self):
@@ -282,7 +292,7 @@ cdef class MT19937:
for i in range(624):
key[i] = self.rng_state.key[i]
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
'state': {'key': key, 'pos': self.rng_state.pos}}
@state.setter
@@ -290,13 +300,13 @@ cdef class MT19937:
if isinstance(value, tuple):
if value[0] != 'MT19937' or len(value) not in (3, 5):
raise ValueError('state is not a legacy MT19937 state')
- value ={'brng': 'MT19937',
+ value ={'bit_generator': 'MT19937',
'state': {'key': value[1], 'pos': value[2]}}
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
key = value['state']['key']
@@ -319,10 +329,10 @@ cdef class MT19937:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -341,24 +351,9 @@ cdef class MT19937:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the core PRNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx
index c67e39854..299398c34 100644
--- a/numpy/random/mtrand.pyx
+++ b/numpy/random/mtrand.pyx
@@ -3,55 +3,59 @@
import operator
import warnings
+import numpy as np
+
+from .bounded_integers import _integers_types
+from .mt19937 import MT19937 as _MT19937
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
from cpython cimport (Py_INCREF, PyFloat_AsDouble)
from libc cimport string
-from libc.stdlib cimport malloc, free
-cimport numpy as np
-import numpy as np
+
cimport cython
+cimport numpy as np
from .bounded_integers cimport *
-from .bounded_integers import _randint_types
from .common cimport *
from .distributions cimport *
from .legacy_distributions cimport *
-from .mt19937 import MT19937 as _MT19937
np.import_array()
cdef class RandomState:
"""
- RandomState(brng=None)
-
- Container for the Mersenne Twister pseudo-random number generator.
-
- `RandomState` exposes a number of methods for generating random numbers
- drawn from a variety of probability distributions. In addition to the
- distribution-specific arguments, each method takes a keyword argument
- `size` that defaults to ``None``. If `size` is ``None``, then a single
- value is generated and returned. If `size` is an integer, then a 1-D
- array filled with generated values is returned. If `size` is a tuple,
- then an array with that shape is filled and returned.
-
- *Compatibility Guarantee*
- A fixed seed and a fixed series of calls to 'RandomState' methods using
- the same parameters will always produce the same results up to roundoff
- error except when the values were incorrect. Incorrect values will be
- fixed and the NumPy version in which the fix was made will be noted in
- the relevant docstring. Extension of existing parameter ranges and the
- addition of new parameters is allowed as long the previous behavior
- remains unchanged.
+ RandomState(bit_generator=None)
+
+ Container for the slow Mersenne Twister pseudo-random number generator.
+ Consider using a different BitGenerator with the Generator container
+ instead.
+
+ `RandomState` and `Generator` expose a number of methods for generating
+ random numbers drawn from a variety of probability distributions. In
+ addition to the distribution-specific arguments, each method takes a
+ keyword argument `size` that defaults to ``None``. If `size` is ``None``,
+ then a single value is generated and returned. If `size` is an integer,
+ then a 1-D array filled with generated values is returned. If `size` is a
+ tuple, then an array with that shape is filled and returned.
+
+ **Compatibility Guarantee**
+
+ A fixed bit generator using a fixed seed and a fixed series of calls to
+ 'RandomState' methods using the same parameters will always produce the
+ same results up to roundoff error except when the values were incorrect.
+ `RandomState` is effectively frozen and will only recieve updates that
+ are required by changes in the the internals of Numpy. More substantial
+ changes, including algorithmic improvements, are reserved for
+ `Generator`.
Parameters
----------
- brng : {None, int, array_like, BasicRNG}, optional
+ bit_generator : {None, int, array_like, BitGenerator}, optional
Random seed used to initialize the pseudo-random number generator or
- an instantized BasicRNG. If an integer or array, used as a seed for
- the MT19937 BasicRNG. Values can be any integer between 0 and
+ an instantized BitGenerator. If an integer or array, used as a seed for
+ the MT19937 BitGenerator. Values can be any integer between 0 and
2**32 - 1 inclusive, an array (or other sequence) of such integers,
or ``None`` (the default). If `seed` is ``None``, then the `MT19937`
- BasicRNG is initialized by reading data from ``/dev/urandom``
+ BitGenerator is initialized by reading data from ``/dev/urandom``
(or the Windows analogue) if available or seed from the clock
otherwise.
@@ -63,44 +67,43 @@ cdef class RandomState:
NumPy-aware, has the advantage that it provides a much larger number
of probability distributions to choose from.
+ See Also
+ --------
+ Generator
+ mt19937.MT19937
+ Bit_Generators
+
"""
- cdef public object _basicrng
- cdef brng_t *_brng
- cdef aug_brng_t *_aug_state
- cdef binomial_t *_binomial
+ cdef public object _bit_generator
+ cdef bitgen_t _bitgen
+ cdef aug_bitgen_t _aug_state
+ cdef binomial_t _binomial
cdef object lock
poisson_lam_max = POISSON_LAM_MAX
- def __init__(self, brng=None):
- if brng is None:
- brng = _MT19937()
- elif not hasattr(brng, 'capsule'):
- brng = _MT19937(brng)
+ def __init__(self, bit_generator=None):
+ if bit_generator is None:
+ bit_generator = _MT19937()
+ elif not hasattr(bit_generator, 'capsule'):
+ bit_generator = _MT19937(bit_generator)
- self._basicrng = brng
- capsule = brng.capsule
- cdef const char *name = "BasicRNG"
+ self._bit_generator = bit_generator
+ capsule = bit_generator.capsule
+ cdef const char *name = "BitGenerator"
if not PyCapsule_IsValid(capsule, name):
- raise ValueError("Invalid brng. The brng must be instantized.")
- self._brng = <brng_t *> PyCapsule_GetPointer(capsule, name)
- self._aug_state = <aug_brng_t *>malloc(sizeof(aug_brng_t))
- self._aug_state.basicrng = self._brng
- self._binomial = <binomial_t *>malloc(sizeof(binomial_t))
+ raise ValueError("Invalid bit generator. The bit generator must "
+ "be instantized.")
+ self._bitgen = (<bitgen_t *> PyCapsule_GetPointer(capsule, name))[0]
+ self._aug_state.bit_generator = &self._bitgen
self._reset_gauss()
- self.lock = brng.lock
-
- def __dealloc__(self):
- if self._binomial:
- free(self._binomial)
- if self._aug_state:
- free(self._aug_state)
+ self.lock = bit_generator.lock
def __repr__(self):
return self.__str__() + ' at 0x{:X}'.format(id(self))
def __str__(self):
_str = self.__class__.__name__
- _str += '(' + self._basicrng.__class__.__name__ + ')'
+ _str += '(' + self._bit_generator.__class__.__name__ + ')'
return _str
# Pickling support:
@@ -113,7 +116,7 @@ cdef class RandomState:
def __reduce__(self):
state = self.get_state(legacy=False)
from ._pickle import __randomstate_ctor
- return __randomstate_ctor, (state['brng'],), state
+ return __randomstate_ctor, (state['bit_generator'],), state
cdef _reset_gauss(self):
self._aug_state.has_gauss = 0
@@ -123,30 +126,28 @@ cdef class RandomState:
"""
seed(self, *args, **kwargs)
- Reseed the basic RNG.
-
- Parameters depend on the basic RNG used.
+ Reseed the BitGenerator.
Notes
-----
- Arguments are directly passed to the basic RNG. This is a convenience
+ Arguments are directly passed to the BitGenerator. This is a convenience
function.
- The best method to access seed is to directly use a basic RNG instance.
- This example demonstrates this best practice.
+ The best method to access seed is to directly use a BitGenerator
+ instance. This example demonstrates this best practice.
>>> from numpy.random import MT19937
>>> from numpy.random import RandomState
- >>> brng = MT19937(123456789)
- >>> rs = RandomState(brng)
- >>> brng.seed(987654321)
+ >>> bit_generator = MT19937(123456789)
+ >>> rs = RandomState(bit_generator)
+ >>> bit_generator.seed(987654321)
These best practice examples are equivalent to
>>> rs = RandomState(MT19937())
>>> rs.seed(987654321)
"""
- self._basicrng.seed(*args, **kwargs)
+ self._bit_generator.seed(*args, **kwargs)
self._reset_gauss()
def get_state(self, legacy=True):
@@ -168,11 +169,11 @@ cdef class RandomState:
4. an integer ``has_gauss``.
5. a float ``cached_gaussian``.
- If `legacy` is False, or the basic RNG is not NT19937, then
+ If `legacy` is False, or the BitGenerator is not NT19937, then
state is returned as a dictionary.
legacy : bool
- Flag indicating the return a legacy tuple state when the basic RNG
+ Flag indicating the return a legacy tuple state when the BitGenerator
is MT19937.
See Also
@@ -186,16 +187,16 @@ cdef class RandomState:
the user should know exactly what he/she is doing.
"""
- st = self._basicrng.state
- if st['brng'] != 'MT19937' and legacy:
+ st = self._bit_generator.state
+ if st['bit_generator'] != 'MT19937' and legacy:
warnings.warn('get_state and legacy can only be used with the '
- 'MT19937 basic RNG. To silence this warning, '
+ 'MT19937 BitGenerator. To silence this warning, '
'set `legacy` to False.', RuntimeWarning)
legacy = False
st['has_gauss'] = self._aug_state.has_gauss
st['gauss'] = self._aug_state.gauss
if legacy:
- return (st['brng'], st['state']['key'], st['state']['pos'],
+ return (st['bit_generator'], st['state']['key'], st['state']['pos'],
st['has_gauss'], st['gauss'])
return st
@@ -205,9 +206,10 @@ cdef class RandomState:
Set the internal state of the generator from a tuple.
- For use if one has reason to manually (re-)set the internal state of the
- Basic RNG used by the RandomState instance. By default, RandomState uses
- the "Mersenne Twister"[1]_ pseudo-random number generating algorithm.
+ For use if one has reason to manually (re-)set the internal state of
+ the bit generator used by the RandomState instance. By default,
+ RandomState uses the "Mersenne Twister"[1]_ pseudo-random number
+ generating algorithm.
Parameters
----------
@@ -220,7 +222,7 @@ cdef class RandomState:
4. an integer ``has_gauss``.
5. a float ``cached_gaussian``.
- If state is a dictionary, it is directly set using the BasicRNGs
+ If state is a dictionary, it is directly set using the BitGenerators
`state` property.
Returns
@@ -251,7 +253,7 @@ cdef class RandomState:
"""
if isinstance(state, dict):
- if 'brng' not in state or 'state' not in state:
+ if 'bit_generator' not in state or 'state' not in state:
raise ValueError('state dictionary is not valid.')
st = state
else:
@@ -260,7 +262,7 @@ cdef class RandomState:
if state[0] != 'MT19937':
raise ValueError('set_state can only be used with legacy MT19937'
'state instances.')
- st = {'brng': state[0],
+ st = {'bit_generator': state[0],
'state': {'key': state[1], 'pos': state[2]}}
if len(state) > 3:
st['has_gauss'] = state[3]
@@ -269,7 +271,7 @@ cdef class RandomState:
self._aug_state.gauss = st.get('gauss', 0.0)
self._aug_state.has_gauss = st.get('has_gauss', 0)
- self._basicrng.state = st
+ self._bit_generator.state = st
def random_sample(self, size=None):
"""
@@ -314,7 +316,16 @@ cdef class RandomState:
"""
cdef double temp
- return double_fill(&random_double_fill, self._brng, size, self.lock, None)
+ return double_fill(&random_double_fill, &self._bitgen, size, self.lock, None)
+
+ def random(self, size=None):
+ """
+ random(size=None)
+
+ Return random floats in the half-open interval [0.0, 1.0). Alias for
+ `random_sample` to ease forward-porting to the new random API.
+ """
+ return self.random_sample(size=size)
def beta(self, a, b, size=None):
"""
@@ -354,7 +365,7 @@ cdef class RandomState:
Drawn samples from the parameterized beta distribution.
"""
- return cont(&legacy_beta, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_beta, &self._aug_state, size, self.lock, 2,
a, 'a', CONS_POSITIVE,
b, 'b', CONS_POSITIVE,
0.0, '', CONS_NONE, None)
@@ -405,7 +416,7 @@ cdef class RandomState:
https://en.wikipedia.org/wiki/Exponential_distribution
"""
- return cont(&legacy_exponential, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_exponential, &self._aug_state, size, self.lock, 1,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE,
@@ -439,7 +450,7 @@ cdef class RandomState:
>>> n = np.random.standard_exponential((3, 8000))
"""
- return cont(&legacy_standard_exponential, self._aug_state, size, self.lock, 0,
+ return cont(&legacy_standard_exponential, &self._aug_state, size, self.lock, 0,
None, None, CONS_NONE,
None, None, CONS_NONE,
None, None, CONS_NONE,
@@ -492,7 +503,7 @@ cdef class RandomState:
if size is None:
with self.lock:
- return random_positive_int(self._brng)
+ return random_positive_int(&self._bitgen)
randoms = <np.ndarray>np.empty(size, dtype=np.int64)
randoms_data = <int64_t*>np.PyArray_DATA(randoms)
@@ -500,7 +511,7 @@ cdef class RandomState:
for i in range(n):
with self.lock, nogil:
- randoms_data[i] = random_positive_int(self._brng)
+ randoms_data[i] = random_positive_int(&self._bitgen)
return randoms
def randint(self, low, high=None, size=None, dtype=int):
@@ -577,34 +588,40 @@ cdef class RandomState:
array([[ 8, 6, 9, 7], # random
[ 1, 16, 9, 12]], dtype=uint8)
"""
- cdef bint use_masked=1
if high is None:
high = low
low = 0
key = np.dtype(dtype).name
- if key not in _randint_types:
+ if key not in _integers_types:
raise TypeError('Unsupported dtype "%s" for randint' % key)
+ # Implementation detail: the use a masked method to generate
+ # bounded uniform integers. Lemire's method is preferrable since it is
+ # faster. randomgen allows a choice, we will always use the slower but
+ # backward compatible one.
+ cdef bint _masked = True
+ cdef bint _endpoint = False
+
if key == 'int32':
- ret = _rand_int32(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_int32(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'int64':
- ret = _rand_int64(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_int64(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'int16':
- ret = _rand_int16(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_int16(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'int8':
- ret = _rand_int8(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_int8(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'uint64':
- ret = _rand_uint64(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_uint64(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'uint32':
- ret = _rand_uint32(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_uint32(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'uint16':
- ret = _rand_uint16(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_uint16(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'uint8':
- ret = _rand_uint8(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_uint8(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
elif key == 'bool':
- ret = _rand_bool(low, high, size, use_masked, False, self._brng, self.lock)
+ ret = _rand_bool(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
if size is None and dtype in (np.bool, np.int, np.long):
if np.array(ret).shape == ():
@@ -915,7 +932,7 @@ cdef class RandomState:
if not np.isfinite(range):
raise OverflowError('Range exceeds valid bounds')
- return cont(&random_uniform, self._brng, size, self.lock, 2,
+ return cont(&random_uniform, &self._bitgen, size, self.lock, 2,
_low, '', CONS_NONE,
range, '', CONS_NONE,
0.0, '', CONS_NONE,
@@ -928,7 +945,7 @@ cdef class RandomState:
arange = <np.ndarray>np.PyArray_EnsureArray(temp)
if not np.all(np.isfinite(arange)):
raise OverflowError('Range exceeds valid bounds')
- return cont(&random_uniform, self._brng, size, self.lock, 2,
+ return cont(&random_uniform, &self._bitgen, size, self.lock, 2,
alow, '', CONS_NONE,
arange, '', CONS_NONE,
0.0, '', CONS_NONE,
@@ -1187,7 +1204,7 @@ cdef class RandomState:
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
"""
- return cont(&legacy_gauss, self._aug_state, size, self.lock, 0,
+ return cont(&legacy_gauss, &self._aug_state, size, self.lock, 0,
None, None, CONS_NONE,
None, None, CONS_NONE,
None, None, CONS_NONE,
@@ -1289,7 +1306,7 @@ cdef class RandomState:
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
"""
- return cont(&legacy_normal, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_normal, &self._aug_state, size, self.lock, 2,
loc, '', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
@@ -1364,7 +1381,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_standard_gamma, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_standard_gamma, &self._aug_state, size, self.lock, 1,
shape, 'shape', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE,
@@ -1443,7 +1460,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_gamma, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_gamma, &self._aug_state, size, self.lock, 2,
shape, 'shape', CONS_NON_NEGATIVE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -1531,7 +1548,7 @@ cdef class RandomState:
level.
"""
- return cont(&legacy_f, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_f, &self._aug_state, size, self.lock, 2,
dfnum, 'dfnum', CONS_POSITIVE,
dfden, 'dfden', CONS_POSITIVE,
0.0, '', CONS_NONE, None)
@@ -1608,7 +1625,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_noncentral_f, self._aug_state, size, self.lock, 3,
+ return cont(&legacy_noncentral_f, &self._aug_state, size, self.lock, 3,
dfnum, 'dfnum', CONS_POSITIVE,
dfden, 'dfden', CONS_POSITIVE,
nonc, 'nonc', CONS_NON_NEGATIVE, None)
@@ -1676,7 +1693,7 @@ cdef class RandomState:
array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272]) # random
"""
- return cont(&legacy_chisquare, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_chisquare, &self._aug_state, size, self.lock, 1,
df, 'df', CONS_POSITIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -1755,7 +1772,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_noncentral_chisquare, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_noncentral_chisquare, &self._aug_state, size, self.lock, 2,
df, 'df', CONS_POSITIVE,
nonc, 'nonc', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -1822,7 +1839,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_standard_cauchy, self._aug_state, size, self.lock, 0,
+ return cont(&legacy_standard_cauchy, &self._aug_state, size, self.lock, 0,
0.0, '', CONS_NONE, 0.0, '', CONS_NONE, 0.0, '', CONS_NONE, None)
def standard_t(self, df, size=None):
@@ -1913,7 +1930,7 @@ cdef class RandomState:
probability of about 99% of being true.
"""
- return cont(&legacy_standard_t, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_standard_t, &self._aug_state, size, self.lock, 1,
df, 'df', CONS_POSITIVE,
0, '', CONS_NONE,
0, '', CONS_NONE,
@@ -1997,7 +2014,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&random_vonmises, self._brng, size, self.lock, 2,
+ return cont(&random_vonmises, &self._bitgen, size, self.lock, 2,
mu, 'mu', CONS_NONE,
kappa, 'kappa', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2067,7 +2084,6 @@ cdef class RandomState:
projects in Sourceforge [1]_. It is one of the so-called
"fat-tailed" distributions.
-
References
----------
.. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of
@@ -2095,7 +2111,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_pareto, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_pareto, &self._aug_state, size, self.lock, 1,
a, 'a', CONS_POSITIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2193,7 +2209,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_weibull, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_weibull, &self._aug_state, size, self.lock, 1,
a, 'a', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2293,7 +2309,7 @@ cdef class RandomState:
>>> plt.title('inverse of stats.pareto(5)')
"""
- return cont(&legacy_power, self._aug_state, size, self.lock, 1,
+ return cont(&legacy_power, &self._aug_state, size, self.lock, 1,
a, 'a', CONS_POSITIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2378,7 +2394,7 @@ cdef class RandomState:
>>> plt.plot(x,g)
"""
- return cont(&random_laplace, self._brng, size, self.lock, 2,
+ return cont(&random_laplace, &self._bitgen, size, self.lock, 2,
loc, 'loc', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2496,7 +2512,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&random_gumbel, self._brng, size, self.lock, 2,
+ return cont(&random_gumbel, &self._bitgen, size, self.lock, 2,
loc, 'loc', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2576,7 +2592,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&random_logistic, self._brng, size, self.lock, 2,
+ return cont(&random_logistic, &self._bitgen, size, self.lock, 2,
loc, 'loc', CONS_NONE,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2686,7 +2702,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_lognormal, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_lognormal, &self._aug_state, size, self.lock, 2,
mean, 'mean', CONS_NONE,
sigma, 'sigma', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE, None)
@@ -2754,7 +2770,7 @@ cdef class RandomState:
0.087300000000000003 # random
"""
- return cont(&random_rayleigh, self._brng, size, self.lock, 1,
+ return cont(&random_rayleigh, &self._bitgen, size, self.lock, 1,
scale, 'scale', CONS_NON_NEGATIVE,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE, None)
@@ -2822,7 +2838,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return cont(&legacy_wald, self._aug_state, size, self.lock, 2,
+ return cont(&legacy_wald, &self._aug_state, size, self.lock, 2,
mean, 'mean', CONS_POSITIVE,
scale, 'scale', CONS_POSITIVE,
0.0, '', CONS_NONE, None)
@@ -2909,7 +2925,7 @@ cdef class RandomState:
raise ValueError("mode > right")
if fleft == fright:
raise ValueError("left == right")
- return cont(&random_triangular, self._brng, size, self.lock, 3,
+ return cont(&random_triangular, &self._bitgen, size, self.lock, 3,
fleft, '', CONS_NONE,
fmode, '', CONS_NONE,
fright, '', CONS_NONE, None)
@@ -2921,7 +2937,7 @@ cdef class RandomState:
if np.any(np.equal(oleft, oright)):
raise ValueError("left == right")
- return cont_broadcast_3(&random_triangular, self._brng, size, self.lock,
+ return cont_broadcast_3(&random_triangular, &self._bitgen, size, self.lock,
oleft, '', CONS_NONE,
omode, '', CONS_NONE,
oright, '', CONS_NONE)
@@ -3044,7 +3060,7 @@ cdef class RandomState:
for i in range(cnt):
_dp = (<double*>np.PyArray_MultiIter_DATA(it, 1))[0]
_in = (<int64_t*>np.PyArray_MultiIter_DATA(it, 2))[0]
- (<int64_t*>np.PyArray_MultiIter_DATA(it, 0))[0] = random_binomial(self._brng, _dp, _in, self._binomial)
+ (<int64_t*>np.PyArray_MultiIter_DATA(it, 0))[0] = random_binomial(&self._bitgen, _dp, _in, &self._binomial)
np.PyArray_MultiIter_NEXT(it)
@@ -3057,7 +3073,7 @@ cdef class RandomState:
if size is None:
with self.lock:
- return random_binomial(self._brng, _dp, _in, self._binomial)
+ return random_binomial(&self._bitgen, _dp, _in, &self._binomial)
randoms = <np.ndarray>np.empty(size, np.int64)
cnt = np.PyArray_SIZE(randoms)
@@ -3065,8 +3081,8 @@ cdef class RandomState:
with self.lock, nogil:
for i in range(cnt):
- randoms_data[i] = random_binomial(self._brng, _dp, _in,
- self._binomial)
+ randoms_data[i] = random_binomial(&self._bitgen, _dp, _in,
+ &self._binomial)
return randoms
@@ -3141,7 +3157,7 @@ cdef class RandomState:
... print(i, "wells drilled, probability of one success =", probability)
"""
- return disc(&legacy_negative_binomial, self._aug_state, size, self.lock, 2, 0,
+ return disc(&legacy_negative_binomial, &self._aug_state, size, self.lock, 2, 0,
n, 'n', CONS_POSITIVE,
p, 'p', CONS_BOUNDED_0_1,
0.0, '', CONS_NONE)
@@ -3212,7 +3228,7 @@ cdef class RandomState:
>>> s = np.random.poisson(lam=(100., 500.), size=(100, 2))
"""
- return disc(&random_poisson, self._brng, size, self.lock, 1, 0,
+ return disc(&random_poisson, &self._bitgen, size, self.lock, 1, 0,
lam, 'lam', CONS_POISSON,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3291,7 +3307,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return disc(&random_zipf, self._brng, size, self.lock, 1, 0,
+ return disc(&random_zipf, &self._bitgen, size, self.lock, 1, 0,
a, 'a', CONS_GT_1,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3342,7 +3358,7 @@ cdef class RandomState:
0.34889999999999999 #random
"""
- return disc(&random_geometric, self._brng, size, self.lock, 1, 0,
+ return disc(&random_geometric, &self._bitgen, size, self.lock, 1, 0,
p, 'p', CONS_BOUNDED_GT_0_1,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3454,14 +3470,14 @@ cdef class RandomState:
if lngood + lnbad < lnsample:
raise ValueError("ngood + nbad < nsample")
- return disc(&random_hypergeometric, self._brng, size, self.lock, 0, 3,
+ return disc(&random_hypergeometric, &self._bitgen, size, self.lock, 0, 3,
lngood, 'ngood', CONS_NON_NEGATIVE,
lnbad, 'nbad', CONS_NON_NEGATIVE,
lnsample, 'nsample', CONS_GTE_1)
if np.any(np.less(np.add(ongood, onbad), onsample)):
raise ValueError("ngood + nbad < nsample")
- return discrete_broadcast_iii(&random_hypergeometric, self._brng, size, self.lock,
+ return discrete_broadcast_iii(&random_hypergeometric, &self._bitgen, size, self.lock,
ongood, 'ngood', CONS_NON_NEGATIVE,
onbad, 'nbad', CONS_NON_NEGATIVE,
onsample, 'nsample', CONS_GTE_1)
@@ -3541,7 +3557,7 @@ cdef class RandomState:
>>> plt.show()
"""
- return disc(&random_logseries, self._brng, size, self.lock, 1, 0,
+ return disc(&random_logseries, &self._bitgen, size, self.lock, 1, 0,
p, 'p', CONS_BOUNDED_0_1,
0.0, '', CONS_NONE,
0.0, '', CONS_NONE)
@@ -3819,7 +3835,7 @@ cdef class RandomState:
offset = 0
with self.lock, nogil:
for i in range(sz // d):
- random_multinomial(self._brng, ni, &mnix[offset], pix, d, self._binomial)
+ random_multinomial(&self._bitgen, ni, &mnix[offset], pix, d, &self._binomial)
offset += d
return multin
@@ -3951,7 +3967,7 @@ cdef class RandomState:
while i < totsize:
acc = 0.0
for j in range(k):
- val_data[i+j] = legacy_standard_gamma(self._aug_state,
+ val_data[i+j] = legacy_standard_gamma(&self._aug_state,
alpha_data[j])
acc = acc + val_data[i + j]
invacc = 1/acc
@@ -4028,7 +4044,7 @@ cdef class RandomState:
buf = np.empty_like(x[0, ...])
with self.lock:
for i in reversed(range(1, n)):
- j = random_interval(self._brng, i)
+ j = random_interval(&self._bitgen, i)
if i == j:
continue # i == j is not needed and memcpy is undefined.
buf[...] = x[j]
@@ -4038,14 +4054,14 @@ cdef class RandomState:
# Untyped path.
with self.lock:
for i in reversed(range(1, n)):
- j = random_interval(self._brng, i)
+ j = random_interval(&self._bitgen, i)
x[i], x[j] = x[j], x[i]
cdef inline _shuffle_raw(self, np.npy_intp n, np.npy_intp itemsize,
np.npy_intp stride, char* data, char* buf):
cdef np.npy_intp i, j
for i in reversed(range(1, n)):
- j = random_interval(self._brng, i)
+ j = random_interval(&self._bitgen, i)
string.memcpy(buf, data + j * stride, itemsize)
string.memcpy(data + j * stride, data + i * stride, itemsize)
string.memcpy(data + i * stride, buf, itemsize)
@@ -4225,3 +4241,4 @@ __all__ = [
'RandomState',
]
+
diff --git a/numpy/random/pcg32.pyx b/numpy/random/pcg32.pyx
deleted file mode 100644
index 64e79dfe1..000000000
--- a/numpy/random/pcg32.pyx
+++ /dev/null
@@ -1,387 +0,0 @@
-from libc.stdlib cimport malloc, free
-from cpython.pycapsule cimport PyCapsule_New
-
-try:
- from threading import Lock
-except ImportError:
- from dummy_threading import Lock
-
-import numpy as np
-cimport numpy as np
-
-from .common cimport *
-from .distributions cimport brng_t
-from .entropy import random_entropy
-
-np.import_array()
-
-
-cdef extern from "src/pcg32/pcg32.h":
-
- cdef struct pcg_state_setseq_64:
- uint64_t state
- uint64_t inc
-
- ctypedef pcg_state_setseq_64 pcg32_random_t
-
- struct s_pcg32_state:
- pcg32_random_t *pcg_state
-
- ctypedef s_pcg32_state pcg32_state
-
- uint64_t pcg32_next64(pcg32_state *state) nogil
- uint32_t pcg32_next32(pcg32_state *state) nogil
- double pcg32_next_double(pcg32_state *state) nogil
- void pcg32_jump(pcg32_state *state)
- void pcg32_advance_state(pcg32_state *state, uint64_t step)
- void pcg32_set_seed(pcg32_state *state, uint64_t seed, uint64_t inc)
-
-cdef uint64_t pcg32_uint64(void* st) nogil:
- return pcg32_next64(<pcg32_state *>st)
-
-cdef uint32_t pcg32_uint32(void *st) nogil:
- return pcg32_next32(<pcg32_state *> st)
-
-cdef double pcg32_double(void* st) nogil:
- return pcg32_next_double(<pcg32_state *>st)
-
-cdef uint64_t pcg32_raw(void* st) nogil:
- return <uint64_t>pcg32_next32(<pcg32_state *> st)
-
-
-cdef class PCG32:
- u"""
- PCG32(seed=None, inc=0)
-
- Container for the PCG-32 pseudo-random number generator.
-
- PCG-32 is a 64-bit implementation of O'Neill's permutation congruential
- generator ([1]_, [2]_). PCG-32 has a period of :math:`2^{64}` and supports
- advancing an arbitrary number of steps as well as :math:`2^{63}` streams.
-
- ``PCG32`` exposes no user-facing API except ``generator``,``state``,
- ``cffi`` and ``ctypes``. Designed for use in a ``RandomGenerator`` object.
-
- **Compatibility Guarantee**
-
- ``PCG32`` makes a guarantee that a fixed seed will always produce the same
- results.
-
- Parameters
- ----------
- seed : {None, long}, optional
- Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**64] or ``None`` (the default).
- If `seed` is ``None``, then ``PCG32`` will try to read data
- from ``/dev/urandom`` (or the Windows analog) if available. If
- unavailable, a 64-bit hash of the time and process ID is used.
- inc : {None, int}, optional
- Stream to return.
- Can be an integer in [0, 2**64] or ``None`` (the default). If `inc` is
- ``None``, then 0 is used. Can be used with the same seed to
- produce multiple streams using other values of inc.
-
- Notes
- -----
- Supports the method advance to advance the PRNG an arbitrary number of
- steps. The state of the PCG-32 PRNG is represented by 2 128-bit unsigned
- integers.
-
- See ``PCG32`` for a similar implementation with a smaller period.
-
- **Parallel Features**
-
- ``PCG32`` can be used in parallel applications in one of two ways.
- The preferable method is to use sub-streams, which are generated by using the
- same value of ``seed`` and incrementing the second value, ``inc``.
-
- >>> from numpy.random import RandomGenerator, PCG32
- >>> rg = [RandomGenerator(PCG32(1234, i + 1)) for i in range(10)]
-
- The alternative method is to call ``advance`` with a different value on
- each instance to produce non-overlapping sequences.
-
- >>> rg = [RandomGenerator(PCG32(1234, i + 1)) for i in range(10)]
- >>> for i in range(10):
- ... rg[i].brng.advance(i * 2**32)
-
- **State and Seeding**
-
- The ``PCG32`` state vector consists of 2 unsigned 64-bit values/
- ``PCG32`` is seeded using a single 64-bit unsigned integer. In addition,
- a second 64-bit unsigned integer is used to set the stream.
-
- References
- ----------
- .. [1] "PCG, A Family of Better Random Number Generators",
- http://www.pcg-random.org/
- .. [2] O'Neill, Melissa E. "PCG: A Family of Simple Fast Space-Efficient
- Statistically Good Algorithms for Random Number Generation"
- """
- cdef pcg32_state *rng_state
- cdef brng_t *_brng
- cdef public object capsule
- cdef object _ctypes
- cdef object _cffi
- cdef object _generator
- cdef public object lock
-
- def __init__(self, seed=None, inc=0):
- self.rng_state = <pcg32_state *>malloc(sizeof(pcg32_state))
- self.rng_state.pcg_state = <pcg32_random_t *>malloc(sizeof(pcg32_random_t))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
- self.seed(seed, inc)
- self.lock = Lock()
-
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &pcg32_uint64
- self._brng.next_uint32 = &pcg32_uint32
- self._brng.next_double = &pcg32_double
- self._brng.next_raw = &pcg32_raw
-
- self._ctypes = None
- self._cffi = None
- self._generator = None
-
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
-
- # Pickling support:
- def __getstate__(self):
- return self.state
-
- def __setstate__(self, state):
- self.state = state
-
- def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
-
- def random_raw(self, size=None, output=True):
- """
- random_raw(self, size=None)
-
- Return randoms as generated by the underlying BasicRNG
-
- Parameters
- ----------
- size : int or tuple of ints, optional
- Output shape. If the given shape is, e.g., ``(m, n, k)``, then
- ``m * n * k`` samples are drawn. Default is None, in which case a
- single value is returned.
- output : bool, optional
- Output values. Used for performance testing since the generated
- values are not returned.
-
- Returns
- -------
- out : uint or ndarray
- Drawn samples.
-
- Notes
- -----
- This method directly exposes the the raw underlying pseudo-random
- number generator. All values are returned as unsigned 64-bit
- values irrespective of the number of bits produced by the PRNG.
-
- See the class docstring for the number of bits returned.
- """
- return random_raw(self._brng, self.lock, size, output)
-
- def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
-
- def seed(self, seed=None, inc=0):
- """
- seed(seed=None, inc=0)
-
- Seed the generator.
-
- This method is called when ``PCG32`` is initialized. It can be
- called again to re-seed the generator. For details, see
- ``PCG32``.
-
- Parameters
- ----------
- seed : int, optional
- Seed for ``PCG32``.
- inc : int, optional
- Increment to use for PCG stream
-
- Raises
- ------
- ValueError
- If seed values are out of range for the PRNG.
- """
- ub = 2 ** 64
- if seed is None:
- try:
- seed = <np.ndarray>random_entropy(2)
- except RuntimeError:
- seed = <np.ndarray>random_entropy(2, 'fallback')
- seed = seed.view(np.uint64).squeeze()
- else:
- err_msg = 'seed must be a scalar integer between 0 and ' \
- '{ub}'.format(ub=ub)
- if not np.isscalar(seed):
- raise TypeError(err_msg)
- if int(seed) != seed:
- raise TypeError(err_msg)
- if seed < 0 or seed > ub:
- raise ValueError(err_msg)
-
- if not np.isscalar(inc):
- raise TypeError('inc must be a scalar integer between 0 '
- 'and {ub}'.format(ub=ub))
- if inc < 0 or inc > ub or int(inc) != inc:
- raise ValueError('inc must be a scalar integer between 0 '
- 'and {ub}'.format(ub=ub))
-
- pcg32_set_seed(self.rng_state, <uint64_t>seed, <uint64_t>inc)
-
- @property
- def state(self):
- """
- Get or set the PRNG state
-
- Returns
- -------
- state : dict
- Dictionary containing the information required to describe the
- state of the PRNG
- """
- return {'brng': self.__class__.__name__,
- 'state': {'state': self.rng_state.pcg_state.state,
- 'inc': self.rng_state.pcg_state.inc}}
-
- @state.setter
- def state(self, value):
- if not isinstance(value, dict):
- raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
- raise ValueError('state must be for a {0} '
- 'PRNG'.format(self.__class__.__name__))
- self.rng_state.pcg_state.state = value['state']['state']
- self.rng_state.pcg_state.inc = value['state']['inc']
-
- def advance(self, delta):
- """
- advance(delta)
-
- Advance the underlying RNG as-if delta draws have occurred.
-
- Parameters
- ----------
- delta : integer, positive
- Number of draws to advance the RNG. Must be less than the
- size state variable in the underlying RNG.
-
- Returns
- -------
- self : PCG32
- RNG advanced delta steps
-
- Notes
- -----
- Advancing a RNG updates the underlying RNG state as-if a given
- number of calls to the underlying RNG have been made. In general
- there is not a one-to-one relationship between the number output
- random values from a particular distribution and the number of
- draws from the core RNG. This occurs for two reasons:
-
- * The random values are simulated using a rejection-based method
- and so, on average, more than one value from the underlying
- RNG is required to generate an single draw.
- * The number of bits required to generate a simulated value
- differs from the number of bits generated by the underlying
- RNG. For example, two 16-bit integer values can be simulated
- from a single draw of a 32-bit RNG.
- """
- pcg32_advance_state(self.rng_state, <uint64_t>delta)
- return self
-
- def jump(self, np.npy_intp iter=1):
- """
- jump(iter=1)
-
- Jumps the state as-if 2**32 random numbers have been generated
-
- Parameters
- ----------
- iter : integer, positive
- Number of times to jump the state of the rng.
-
- Returns
- -------
- self : PCG32
- RNG jumped iter times
- """
- return self.advance(iter * 2**32)
-
- @property
- def ctypes(self):
- """
- ctypes interface
-
- Returns
- -------
- interface : namedtuple
- Named tuple containing ctypes wrapper
-
- * state_address - Memory address of the state struct
- * state - pointer to the state struct
- * next_uint64 - function pointer to produce 64 bit integers
- * next_uint32 - function pointer to produce 32 bit integers
- * next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
- """
- if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
-
- return self._ctypes
-
- @property
- def cffi(self):
- """
- CFFI interface
-
- Returns
- -------
- interface : namedtuple
- Named tuple containing CFFI wrapper
-
- * state_address - Memory address of the state struct
- * state - pointer to the state struct
- * next_uint64 - function pointer to produce 64 bit integers
- * next_uint32 - function pointer to produce 32 bit integers
- * next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
- """
- if self._cffi is not None:
- return self._cffi
- self._cffi = prepare_cffi(self._brng)
- return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the core PRNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/pcg64.pyx b/numpy/random/pcg64.pyx
deleted file mode 100644
index af98bbd84..000000000
--- a/numpy/random/pcg64.pyx
+++ /dev/null
@@ -1,426 +0,0 @@
-from libc.stdlib cimport malloc, free
-from cpython.pycapsule cimport PyCapsule_New
-
-try:
- from threading import Lock
-except ImportError:
- from dummy_threading import Lock
-
-import numpy as np
-cimport numpy as np
-
-from .common cimport *
-from .distributions cimport brng_t
-from .entropy import random_entropy
-
-np.import_array()
-
-# IF PCG_EMULATED_MATH==1:
-cdef extern from "src/pcg64/pcg64.h":
- # Use int as generic type, actual type read from pcg64.h and is platform dependent
- ctypedef int pcg64_random_t
-
- struct s_pcg64_state:
- pcg64_random_t *pcg_state
- int has_uint32
- uint32_t uinteger
-
- ctypedef s_pcg64_state pcg64_state
-
- uint64_t pcg64_next64(pcg64_state *state) nogil
- uint32_t pcg64_next32(pcg64_state *state) nogil
- void pcg64_jump(pcg64_state *state)
- void pcg64_advance(pcg64_state *state, uint64_t *step)
- void pcg64_set_seed(pcg64_state *state, uint64_t *seed, uint64_t *inc)
- void pcg64_get_state(pcg64_state *state, uint64_t *state_arr, int *has_uint32, uint32_t *uinteger)
- void pcg64_set_state(pcg64_state *state, uint64_t *state_arr, int has_uint32, uint32_t uinteger)
-
-cdef uint64_t pcg64_uint64(void* st) nogil:
- return pcg64_next64(<pcg64_state *>st)
-
-cdef uint32_t pcg64_uint32(void *st) nogil:
- return pcg64_next32(<pcg64_state *> st)
-
-cdef double pcg64_double(void* st) nogil:
- return uint64_to_double(pcg64_next64(<pcg64_state *>st))
-
-cdef class PCG64:
- u"""
- PCG64(seed=None, inc=0)
-
- Container for the PCG-64 pseudo-random number generator.
-
- PCG-64 is a 128-bit implementation of O'Neill's permutation congruential
- generator ([1]_, [2]_). PCG-64 has a period of :math:`2^{128}` and supports
- advancing an arbitrary number of steps as well as :math:`2^{127}` streams.
-
- ``PCG64`` exposes no user-facing API except ``generator``,``state``,
- ``cffi`` and ``ctypes``. Designed for use in a ``RandomGenerator`` object.
-
- **Compatibility Guarantee**
-
- ``PCG64`` makes a guarantee that a fixed seed will always produce the same
- results.
-
- Parameters
- ----------
- seed : {None, long}, optional
- Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**128] or ``None`` (the default).
- If `seed` is ``None``, then ``PCG64`` will try to read data
- from ``/dev/urandom`` (or the Windows analog) if available. If
- unavailable, a 64-bit hash of the time and process ID is used.
- inc : {None, int}, optional
- Stream to return.
- Can be an integer in [0, 2**128] or ``None`` (the default). If `inc` is
- ``None``, then 0 is used. Can be used with the same seed to
- produce multiple streams using other values of inc.
-
- Notes
- -----
- Supports the method advance to advance the RNG an arbitrary number of
- steps. The state of the PCG-64 RNG is represented by 2 128-bit unsigned
- integers.
-
- See ``PCG32`` for a similar implementation with a smaller period.
-
- **Parallel Features**
-
- ``PCG64`` can be used in parallel applications in one of two ways.
- The preferable method is to use sub-streams, which are generated by using the
- same value of ``seed`` and incrementing the second value, ``inc``.
-
- >>> from numpy.random import RandomGenerator, PCG64
- >>> rg = [RandomGenerator(PCG64(1234, i + 1)) for i in range(10)]
-
- The alternative method is to call ``advance`` with a different value on
- each instance to produce non-overlapping sequences.
-
- >>> rg = [RandomGenerator(PCG64(1234, i + 1)) for i in range(10)]
- >>> for i in range(10):
- ... rg[i].brng.advance(i * 2**64)
-
- **State and Seeding**
-
- The ``PCG64`` state vector consists of 2 unsigned 128-bit values,
- which are represented externally as python longs (2.x) or ints (Python 3+).
- ``PCG64`` is seeded using a single 128-bit unsigned integer
- (Python long/int). In addition, a second 128-bit unsigned integer is used
- to set the stream.
-
- References
- ----------
- .. [1] "PCG, A Family of Better Random Number Generators",
- http://www.pcg-random.org/
- .. [2] O'Neill, Melissa E. "PCG: A Family of Simple Fast Space-Efficient
- Statistically Good Algorithms for Random Number Generation"
- """
- cdef pcg64_state *rng_state
- cdef brng_t *_brng
- cdef public object capsule
- cdef object _ctypes
- cdef object _cffi
- cdef object _generator
- cdef public object lock
-
- def __init__(self, seed=None, inc=0):
- self.rng_state = <pcg64_state *>malloc(sizeof(pcg64_state))
- self.rng_state.pcg_state = <pcg64_random_t *>malloc(sizeof(pcg64_random_t))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
- self.seed(seed, inc)
- self.lock = Lock()
-
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &pcg64_uint64
- self._brng.next_uint32 = &pcg64_uint32
- self._brng.next_double = &pcg64_double
- self._brng.next_raw = &pcg64_uint64
-
- self._ctypes = None
- self._cffi = None
- self._generator = None
-
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
-
- # Pickling support:
- def __getstate__(self):
- return self.state
-
- def __setstate__(self, state):
- self.state = state
-
- def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
-
- cdef _reset_state_variables(self):
- self.rng_state.has_uint32 = 0
- self.rng_state.uinteger = 0
-
- def random_raw(self, size=None, output=True):
- """
- random_raw(self, size=None)
-
- Return randoms as generated by the underlying BasicRNG
-
- Parameters
- ----------
- size : int or tuple of ints, optional
- Output shape. If the given shape is, e.g., ``(m, n, k)``, then
- ``m * n * k`` samples are drawn. Default is None, in which case a
- single value is returned.
- output : bool, optional
- Output values. Used for performance testing since the generated
- values are not returned.
-
- Returns
- -------
- out : uint or ndarray
- Drawn samples.
-
- Notes
- -----
- This method directly exposes the the raw underlying pseudo-random
- number generator. All values are returned as unsigned 64-bit
- values irrespective of the number of bits produced by the PRNG.
-
- See the class docstring for the number of bits returned.
- """
- return random_raw(self._brng, self.lock, size, output)
-
- def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
-
- def seed(self, seed=None, inc=0):
- """
- seed(seed=None, inc=0)
-
- Seed the generator.
-
- This method is called when ``PCG64`` is initialized. It can be
- called again to re-seed the generator. For details, see
- ``PCG64``.
-
- Parameters
- ----------
- seed : int, optional
- Seed for ``PCG64``.
- inc : int, optional
- Increment to use for PCG stream
-
- Raises
- ------
- ValueError
- If seed values are out of range for the RNG.
-
- """
- cdef np.ndarray _seed, _inc
- ub = 2 ** 128
- if seed is None:
- try:
- _seed = <np.ndarray>random_entropy(4)
- except RuntimeError:
- _seed = <np.ndarray>random_entropy(4, 'fallback')
- _seed = <np.ndarray>_seed.view(np.uint64)
- else:
- err_msg = 'seed must be a scalar integer between 0 and ' \
- '{ub}'.format(ub=ub)
- if not np.isscalar(seed):
- raise TypeError(err_msg)
- if int(seed) != seed:
- raise TypeError(err_msg)
- if seed < 0 or seed > ub:
- raise ValueError(err_msg)
- _seed = <np.ndarray>np.empty(2, np.uint64)
- _seed[0] = int(seed) // 2**64
- _seed[1] = int(seed) % 2**64
-
- if not np.isscalar(inc):
- raise TypeError('inc must be a scalar integer between 0 and {ub}'.format(ub=ub))
- if inc < 0 or inc > ub or int(inc) != inc:
- raise ValueError('inc must be a scalar integer between 0 and {ub}'.format(ub=ub))
- _inc = <np.ndarray>np.empty(2, np.uint64)
- _inc[0] = int(inc) // 2**64
- _inc[1] = int(inc) % 2**64
-
- pcg64_set_seed(self.rng_state, <uint64_t *>_seed.data, <uint64_t *>_inc.data)
- self._reset_state_variables()
-
- @property
- def state(self):
- """
- Get or set the RNG state
-
- Returns
- -------
- state : dict
- Dictionary containing the information required to describe the
- state of the RNG
- """
- cdef np.ndarray state_vec
- cdef int has_uint32
- cdef uint32_t uinteger
-
- # state_vec is state.high, state.low, inc.high, inc.low
- state_vec = <np.ndarray>np.empty(4, dtype=np.uint64)
- pcg64_get_state(self.rng_state, <uint64_t *>state_vec.data, &has_uint32, &uinteger)
- state = int(state_vec[0]) * 2**64 + int(state_vec[1])
- inc = int(state_vec[2]) * 2**64 + int(state_vec[3])
- return {'brng': self.__class__.__name__,
- 'state': {'state': state, 'inc': inc},
- 'has_uint32': has_uint32,
- 'uinteger': uinteger}
-
- @state.setter
- def state(self, value):
- cdef np.ndarray state_vec
- cdef int has_uint32
- cdef uint32_t uinteger
- if not isinstance(value, dict):
- raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
- raise ValueError('state must be for a {0} '
- 'RNG'.format(self.__class__.__name__))
- state_vec = <np.ndarray>np.empty(4, dtype=np.uint64)
- state_vec[0] = value['state']['state'] // 2 ** 64
- state_vec[1] = value['state']['state'] % 2 ** 64
- state_vec[2] = value['state']['inc'] // 2 ** 64
- state_vec[3] = value['state']['inc'] % 2 ** 64
- has_uint32 = value['has_uint32']
- uinteger = value['uinteger']
- pcg64_set_state(self.rng_state, <uint64_t *>state_vec.data, has_uint32, uinteger)
-
- def advance(self, delta):
- """
- advance(delta)
-
- Advance the underlying RNG as-if delta draws have occurred.
-
- Parameters
- ----------
- delta : integer, positive
- Number of draws to advance the RNG. Must be less than the
- size state variable in the underlying RNG.
-
- Returns
- -------
- self : PCG64
- RNG advanced delta steps
-
- Notes
- -----
- Advancing a RNG updates the underlying RNG state as-if a given
- number of calls to the underlying RNG have been made. In general
- there is not a one-to-one relationship between the number output
- random values from a particular distribution and the number of
- draws from the core RNG. This occurs for two reasons:
-
- * The random values are simulated using a rejection-based method
- and so, on average, more than one value from the underlying
- RNG is required to generate an single draw.
- * The number of bits required to generate a simulated value
- differs from the number of bits generated by the underlying
- RNG. For example, two 16-bit integer values can be simulated
- from a single draw of a 32-bit RNG.
-
- Advancing the RNG state resets any pre-computed random numbers.
- This is required to ensure exact reproducibility.
- """
- cdef np.ndarray d = np.empty(2, dtype=np.uint64)
- d[0] = delta // 2**64
- d[1] = delta % 2**64
- pcg64_advance(self.rng_state, <uint64_t *>d.data)
- self._reset_state_variables()
- return self
-
- def jump(self, np.npy_intp iter=1):
- """
- jump(iter=1)
-
- Jumps the state as-if 2**64 random numbers have been generated
-
- Parameters
- ----------
- iter : integer, positive
- Number of times to jump the state of the rng.
-
- Returns
- -------
- self : PCG64
- RNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is required
- to ensure exact reproducibility.
- """
- return self.advance(iter * 2**64)
-
- @property
- def ctypes(self):
- """
- ctypes interface
-
- Returns
- -------
- interface : namedtuple
- Named tuple containing ctypes wrapper
-
- * state_address - Memory address of the state struct
- * state - pointer to the state struct
- * next_uint64 - function pointer to produce 64 bit integers
- * next_uint32 - function pointer to produce 32 bit integers
- * next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
- """
- if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
-
- return self._ctypes
-
- @property
- def cffi(self):
- """
- CFFI interface
-
- Returns
- -------
- interface : namedtuple
- Named tuple containing CFFI wrapper
-
- * state_address - Memory address of the state struct
- * state - pointer to the state struct
- * next_uint64 - function pointer to produce 64 bit integers
- * next_uint32 - function pointer to produce 32 bit integers
- * next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
- """
- if self._cffi is not None:
- return self._cffi
- self._cffi = prepare_cffi(self._brng)
- return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator using this instance as the core RNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/philox.pyx b/numpy/random/philox.pyx
index 4ca38bb11..19fd64399 100644
--- a/numpy/random/philox.pyx
+++ b/numpy/random/philox.pyx
@@ -1,4 +1,3 @@
-from libc.stdlib cimport malloc, free
from cpython.pycapsule cimport PyCapsule_New
try:
@@ -9,10 +8,9 @@ except ImportError:
import numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
-
np.import_array()
DEF PHILOX_BUFFER_SIZE=4
@@ -89,69 +87,59 @@ cdef class Philox:
the sequence in increments of :math:`2^{128}`. These features allow
multiple non-overlapping sequences to be generated.
- ``Philox`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
+ ``Philox`` provides a capsule containing function pointers that produce
+ doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
- **Compatibility Guarantee**
+ See ``ThreeFry`` for a closely related PRNG.
- ``Philox`` guarantees that a fixed seed will always produce the
- same results.
+ **State and Seeding**
- See ``Philox`` for a closely related PRNG implementation.
+ The ``Philox`` state vector consists of a 2 256-bit values encoded as
+ 4-element uint64 arrays. One is a counter which is incremented by 1 for
+ every 4 64-bit randoms produced. The second is a key which determined
+ the sequence produced. Using different keys produces independent
+ sequences.
+
+ ``Philox`` is seeded using either a single 64-bit unsigned integer
+ or a vector of 64-bit unsigned integers. In either case, the seed is
+ used as an input for a second random number generator,
+ SplitMix64, and the output of this PRNG function is used as the initial state.
+ Using a single 64-bit value for the seed can only initialize a small range of
+ the possible initial state values.
**Parallel Features**
- ``Philox`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{128}` random numbers have been generated. Alternatively,
- ``advance`` can be used to advance the counter for an abritrary number of
- positive steps in [0, 2**256). When using ``jump``, all generators should
- be initialized with the same seed to ensure that the segments come from
- the same sequence. Alternatively, ``Philox`` can be used
- in parallel applications by using a sequence of distinct keys where each
- instance uses different key.
+ ``Philox`` can be used in parallel applications by calling the ``jumped``
+ method to advances the state as-if :math:`2^{128}` random numbers have
+ been generated. Alternatively, ``advance`` can be used to advance the
+ counter for any positive step in [0, 2**256). When using ``jumped``, all
+ generators should be chained to ensure that the segments come from the same
+ sequence.
- >>> from numpy.random import RandomGenerator, Philox
- >>> rg = [RandomGenerator(Philox(1234)) for _ in range(10)]
- # Advance each Philox instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
+ >>> from numpy.random import Generator, Philox
+ >>> bit_generator = Philox(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... bit_generator = bit_generator.jumped()
- Using distinct keys produces independent streams
+ Alternatively, ``Philox`` can be used in parallel applications by using
+ a sequence of distinct keys where each instance uses different key.
- >>> key = 2**96 + 2**32 + 2**65 + 2**33 + 2**17 + 2**9
- >>> rg = [RandomGenerator(Philox(key=key+i)) for i in range(10)]
+ >>> key = 2**96 + 2**33 + 2**17 + 2**9
+ >>> rg = [Generator(Philox(key=key+i)) for i in range(10)]
- **State and Seeding**
+ **Compatibility Guarantee**
- The ``Philox`` state vector consists of a 256-bit counter encoded as a
- 4-element uint64 array and a 128-bit key encoded as a 2-element uint64
- array. The counter is incremented by 1 for every 4 64-bit randoms
- produced. The key determines the sequence produced. Using different
- keys produces independent sequences.
-
- ``Philox`` is seeded using either a single 64-bit unsigned integer
- or a vector of 64-bit unsigned integers. In either case, the input seed is
- used as an input (or inputs) for another simple random number generator,
- Splitmix64, and the output of this PRNG function is used as the initial state.
- Using a single 64-bit value for the seed can only initialize a small range of
- the possible initial state values. When using an array, the SplitMix64 state
- for producing the ith component of the initial state is XORd with the ith
- value of the seed array until the seed array is exhausted. When using an array
- the initial state for the SplitMix64 state is 0 so that using a single element
- array and using the same value as a scalar will produce the same initial state.
+ ``Philox`` makes a guarantee that a fixed seed and will always produce
+ the same random integer stream.
Examples
--------
- >>> from numpy.random import RandomGenerator, Philox
- >>> rg = RandomGenerator(Philox(1234))
- >>> rg.standard_normal()
- 0.123 # random
-
- Identical method using only Philox
-
- >>> rg = Philox(1234).generator
+ >>> from numpy.random import Generator, Philox
+ >>> rg = Generator(Philox(1234))
>>> rg.standard_normal()
0.123 # random
@@ -162,36 +150,32 @@ cdef class Philox:
the International Conference for High Performance Computing,
Networking, Storage and Analysis (SC11), New York, NY: ACM, 2011.
"""
- cdef philox_state *rng_state
- cdef brng_t *_brng
+ cdef philox_state rng_state
+ cdef philox4x64_key_t philox_key
+ cdef philox4x64_ctr_t philox_ctr
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None, counter=None, key=None):
- self.rng_state = <philox_state *> malloc(sizeof(philox_state))
- self.rng_state.ctr = <philox4x64_ctr_t *> malloc(
- sizeof(philox4x64_ctr_t))
- self.rng_state.key = <philox4x64_key_t *> malloc(
- sizeof(philox4x64_key_t))
- self._brng = <brng_t *> malloc(sizeof(brng_t))
+ self.rng_state.ctr = &self.philox_ctr
+ self.rng_state.key = &self.philox_key
self.seed(seed, counter, key)
self.lock = Lock()
- self._brng.state = <void *> self.rng_state
- self._brng.next_uint64 = &philox_uint64
- self._brng.next_uint32 = &philox_uint32
- self._brng.next_double = &philox_double
- self._brng.next_raw = &philox_uint64
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &philox_uint64
+ self._bitgen.next_uint32 = &philox_uint32
+ self._bitgen.next_double = &philox_double
+ self._bitgen.next_raw = &philox_uint64
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = 'BasicRNG'
- self.capsule = PyCapsule_New(<void *> self._brng, name, NULL)
+ cdef const char *name = 'BitGenerator'
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -201,18 +185,8 @@ cdef class Philox:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state.ctr)
- free(self.rng_state.key)
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.has_uint32 = 0
@@ -225,7 +199,7 @@ cdef class Philox:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -250,10 +224,10 @@ cdef class Philox:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None, counter=None, key=None):
"""
@@ -333,7 +307,7 @@ cdef class Philox:
buffer[i] = self.rng_state.buffer[i]
state = {'counter': ctr, 'key': key}
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
'state': state,
'buffer': buffer,
'buffer_pos': self.rng_state.buffer_pos,
@@ -344,8 +318,8 @@ cdef class Philox:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
for i in range(4):
@@ -359,28 +333,45 @@ cdef class Philox:
self.rng_state.uinteger = value['uinteger']
self.rng_state.buffer_pos = value['buffer_pos']
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**128 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
+ """
+ self.advance(iter * 2 ** 128)
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(128 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
Returns
-------
- self : Philox
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is
- required to ensure exact reproducibility.
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
"""
- return self.advance(iter * 2 ** 128)
+ cdef Philox bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
def advance(self, delta):
"""
@@ -420,7 +411,7 @@ cdef class Philox:
"""
cdef np.ndarray delta_a
delta_a = int_to_array(delta, 'step', 256, 64)
- philox_advance(<uint64_t *> delta_a.data, self.rng_state)
+ philox_advance(<uint64_t *> delta_a.data, &self.rng_state)
self._reset_state_variables()
return self
@@ -439,10 +430,10 @@ cdef class Philox:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the BitGenerator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -461,24 +452,9 @@ cdef class Philox:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the BitGenerator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the core PRNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/setup.py b/numpy/random/setup.py
index fc7c9a886..5f3a48783 100644
--- a/numpy/random/setup.py
+++ b/numpy/random/setup.py
@@ -75,7 +75,6 @@ def configuration(parent_package='',top_path=None):
sys.argv.remove('--no-sse2')
DEBUG = False
- PCG_EMULATED_MATH = False
EXTRA_LINK_ARGS = []
EXTRA_LIBRARIES = ['m'] if os.name != 'nt' else []
EXTRA_COMPILE_ARGS = [] if os.name == 'nt' else [
@@ -88,18 +87,6 @@ def configuration(parent_package='',top_path=None):
if sys.version_info < (3, 0):
EXTRA_INCLUDE_DIRS += [join(MOD_DIR, 'src', 'common')]
- PCG64_DEFS = []
- # TODO: remove the unconditional forced emulation, move code from pcg64.pyx
- # to an #ifdef
- if 1 or sys.maxsize < 2 ** 32 or os.name == 'nt':
- # Force emulated mode here
- PCG_EMULATED_MATH = True
- PCG64_DEFS += [('PCG_FORCE_EMULATED_128BIT_MATH', '1')]
-
- if struct.calcsize('P') < 8:
- PCG_EMULATED_MATH = True
- defs.append(('PCG_EMULATED_MATH', int(PCG_EMULATED_MATH)))
-
DSFMT_DEFS = [('DSFMT_MEXP', '19937')]
if USE_SSE2:
if os.name == 'nt':
@@ -112,7 +99,6 @@ def configuration(parent_package='',top_path=None):
config.add_extension('entropy',
sources=['entropy.c', 'src/entropy/entropy.c'],
- include_dirs=[join('randomgen', 'src', 'entropy')],
libraries=EXTRA_LIBRARIES,
extra_compile_args=EXTRA_COMPILE_ARGS,
extra_link_args=EXTRA_LINK_ARGS,
@@ -148,15 +134,10 @@ def configuration(parent_package='',top_path=None):
define_macros=defs,
)
for gen in ['philox', 'threefry', 'threefry32',
- 'xoroshiro128', 'xorshift1024', 'xoshiro256starstar',
- 'xoshiro512starstar',
- 'pcg64', 'pcg32',
+ 'xoroshiro128', 'xorshift1024', 'xoshiro256',
+ 'xoshiro512',
]:
# gen.pyx, src/gen/gen.c
- if gen == 'pcg64':
- _defs = defs + PCG64_DEFS
- else:
- _defs = defs
config.add_extension(gen,
sources=['{0}.c'.format(gen), 'src/{0}/{0}.c'.format(gen)],
include_dirs=['.', 'src', join('src', gen)],
@@ -164,7 +145,7 @@ def configuration(parent_package='',top_path=None):
extra_compile_args=EXTRA_COMPILE_ARGS,
extra_link_args=EXTRA_LINK_ARGS,
depends=['%s.pyx' % gen],
- define_macros=_defs,
+ define_macros=defs,
)
for gen in ['common']:
# gen.pyx
diff --git a/numpy/random/src/common/LICENSE.md b/numpy/random/src/common/LICENSE.md
deleted file mode 100644
index 71bf8cf46..000000000
--- a/numpy/random/src/common/LICENSE.md
+++ /dev/null
@@ -1,29 +0,0 @@
-ISO C9x compliant stdint.h for Microsoft Visual Studio
-Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
-
-Copyright (c) 2006-2013 Alexander Chemeris
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the product nor the names of its contributors may
- be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/numpy/random/src/common/inttypes.h b/numpy/random/src/common/inttypes.h
deleted file mode 100644
index 8f8b61108..000000000
--- a/numpy/random/src/common/inttypes.h
+++ /dev/null
@@ -1,306 +0,0 @@
-// ISO C9x compliant inttypes.h for Microsoft Visual Studio
-// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
-//
-// Copyright (c) 2006-2013 Alexander Chemeris
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the product nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef _MSC_VER // [
-#error "Use this header only with Microsoft Visual C++ compilers!"
-#endif // _MSC_VER ]
-
-#ifndef _MSC_INTTYPES_H_ // [
-#define _MSC_INTTYPES_H_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-#include "stdint.h"
-
-// 7.8 Format conversion of integer types
-
-typedef struct {
- intmax_t quot;
- intmax_t rem;
-} imaxdiv_t;
-
-// 7.8.1 Macros for format specifiers
-
-#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
-
-// The fprintf macros for signed integers are:
-#define PRId8 "d"
-#define PRIi8 "i"
-#define PRIdLEAST8 "d"
-#define PRIiLEAST8 "i"
-#define PRIdFAST8 "d"
-#define PRIiFAST8 "i"
-
-#define PRId16 "hd"
-#define PRIi16 "hi"
-#define PRIdLEAST16 "hd"
-#define PRIiLEAST16 "hi"
-#define PRIdFAST16 "hd"
-#define PRIiFAST16 "hi"
-
-#define PRId32 "I32d"
-#define PRIi32 "I32i"
-#define PRIdLEAST32 "I32d"
-#define PRIiLEAST32 "I32i"
-#define PRIdFAST32 "I32d"
-#define PRIiFAST32 "I32i"
-
-#define PRId64 "I64d"
-#define PRIi64 "I64i"
-#define PRIdLEAST64 "I64d"
-#define PRIiLEAST64 "I64i"
-#define PRIdFAST64 "I64d"
-#define PRIiFAST64 "I64i"
-
-#define PRIdMAX "I64d"
-#define PRIiMAX "I64i"
-
-#define PRIdPTR "Id"
-#define PRIiPTR "Ii"
-
-// The fprintf macros for unsigned integers are:
-#define PRIo8 "o"
-#define PRIu8 "u"
-#define PRIx8 "x"
-#define PRIX8 "X"
-#define PRIoLEAST8 "o"
-#define PRIuLEAST8 "u"
-#define PRIxLEAST8 "x"
-#define PRIXLEAST8 "X"
-#define PRIoFAST8 "o"
-#define PRIuFAST8 "u"
-#define PRIxFAST8 "x"
-#define PRIXFAST8 "X"
-
-#define PRIo16 "ho"
-#define PRIu16 "hu"
-#define PRIx16 "hx"
-#define PRIX16 "hX"
-#define PRIoLEAST16 "ho"
-#define PRIuLEAST16 "hu"
-#define PRIxLEAST16 "hx"
-#define PRIXLEAST16 "hX"
-#define PRIoFAST16 "ho"
-#define PRIuFAST16 "hu"
-#define PRIxFAST16 "hx"
-#define PRIXFAST16 "hX"
-
-#define PRIo32 "I32o"
-#define PRIu32 "I32u"
-#define PRIx32 "I32x"
-#define PRIX32 "I32X"
-#define PRIoLEAST32 "I32o"
-#define PRIuLEAST32 "I32u"
-#define PRIxLEAST32 "I32x"
-#define PRIXLEAST32 "I32X"
-#define PRIoFAST32 "I32o"
-#define PRIuFAST32 "I32u"
-#define PRIxFAST32 "I32x"
-#define PRIXFAST32 "I32X"
-
-#define PRIo64 "I64o"
-#define PRIu64 "I64u"
-#define PRIx64 "I64x"
-#define PRIX64 "I64X"
-#define PRIoLEAST64 "I64o"
-#define PRIuLEAST64 "I64u"
-#define PRIxLEAST64 "I64x"
-#define PRIXLEAST64 "I64X"
-#define PRIoFAST64 "I64o"
-#define PRIuFAST64 "I64u"
-#define PRIxFAST64 "I64x"
-#define PRIXFAST64 "I64X"
-
-#define PRIoMAX "I64o"
-#define PRIuMAX "I64u"
-#define PRIxMAX "I64x"
-#define PRIXMAX "I64X"
-
-#define PRIoPTR "Io"
-#define PRIuPTR "Iu"
-#define PRIxPTR "Ix"
-#define PRIXPTR "IX"
-
-// The fscanf macros for signed integers are:
-#define SCNd8 "d"
-#define SCNi8 "i"
-#define SCNdLEAST8 "d"
-#define SCNiLEAST8 "i"
-#define SCNdFAST8 "d"
-#define SCNiFAST8 "i"
-
-#define SCNd16 "hd"
-#define SCNi16 "hi"
-#define SCNdLEAST16 "hd"
-#define SCNiLEAST16 "hi"
-#define SCNdFAST16 "hd"
-#define SCNiFAST16 "hi"
-
-#define SCNd32 "ld"
-#define SCNi32 "li"
-#define SCNdLEAST32 "ld"
-#define SCNiLEAST32 "li"
-#define SCNdFAST32 "ld"
-#define SCNiFAST32 "li"
-
-#define SCNd64 "I64d"
-#define SCNi64 "I64i"
-#define SCNdLEAST64 "I64d"
-#define SCNiLEAST64 "I64i"
-#define SCNdFAST64 "I64d"
-#define SCNiFAST64 "I64i"
-
-#define SCNdMAX "I64d"
-#define SCNiMAX "I64i"
-
-#ifdef _WIN64 // [
-# define SCNdPTR "I64d"
-# define SCNiPTR "I64i"
-#else // _WIN64 ][
-# define SCNdPTR "ld"
-# define SCNiPTR "li"
-#endif // _WIN64 ]
-
-// The fscanf macros for unsigned integers are:
-#define SCNo8 "o"
-#define SCNu8 "u"
-#define SCNx8 "x"
-#define SCNX8 "X"
-#define SCNoLEAST8 "o"
-#define SCNuLEAST8 "u"
-#define SCNxLEAST8 "x"
-#define SCNXLEAST8 "X"
-#define SCNoFAST8 "o"
-#define SCNuFAST8 "u"
-#define SCNxFAST8 "x"
-#define SCNXFAST8 "X"
-
-#define SCNo16 "ho"
-#define SCNu16 "hu"
-#define SCNx16 "hx"
-#define SCNX16 "hX"
-#define SCNoLEAST16 "ho"
-#define SCNuLEAST16 "hu"
-#define SCNxLEAST16 "hx"
-#define SCNXLEAST16 "hX"
-#define SCNoFAST16 "ho"
-#define SCNuFAST16 "hu"
-#define SCNxFAST16 "hx"
-#define SCNXFAST16 "hX"
-
-#define SCNo32 "lo"
-#define SCNu32 "lu"
-#define SCNx32 "lx"
-#define SCNX32 "lX"
-#define SCNoLEAST32 "lo"
-#define SCNuLEAST32 "lu"
-#define SCNxLEAST32 "lx"
-#define SCNXLEAST32 "lX"
-#define SCNoFAST32 "lo"
-#define SCNuFAST32 "lu"
-#define SCNxFAST32 "lx"
-#define SCNXFAST32 "lX"
-
-#define SCNo64 "I64o"
-#define SCNu64 "I64u"
-#define SCNx64 "I64x"
-#define SCNX64 "I64X"
-#define SCNoLEAST64 "I64o"
-#define SCNuLEAST64 "I64u"
-#define SCNxLEAST64 "I64x"
-#define SCNXLEAST64 "I64X"
-#define SCNoFAST64 "I64o"
-#define SCNuFAST64 "I64u"
-#define SCNxFAST64 "I64x"
-#define SCNXFAST64 "I64X"
-
-#define SCNoMAX "I64o"
-#define SCNuMAX "I64u"
-#define SCNxMAX "I64x"
-#define SCNXMAX "I64X"
-
-#ifdef _WIN64 // [
-# define SCNoPTR "I64o"
-# define SCNuPTR "I64u"
-# define SCNxPTR "I64x"
-# define SCNXPTR "I64X"
-#else // _WIN64 ][
-# define SCNoPTR "lo"
-# define SCNuPTR "lu"
-# define SCNxPTR "lx"
-# define SCNXPTR "lX"
-#endif // _WIN64 ]
-
-#endif // __STDC_FORMAT_MACROS ]
-
-// 7.8.2 Functions for greatest-width integer types
-
-// 7.8.2.1 The imaxabs function
-#define imaxabs _abs64
-
-// 7.8.2.2 The imaxdiv function
-
-// This is modified version of div() function from Microsoft's div.c found
-// in %MSVC.NET%\crt\src\div.c
-#ifdef STATIC_IMAXDIV // [
-static
-#else // STATIC_IMAXDIV ][
-_inline
-#endif // STATIC_IMAXDIV ]
-imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
-{
- imaxdiv_t result;
-
- result.quot = numer / denom;
- result.rem = numer % denom;
-
- if (numer < 0 && result.rem > 0) {
- // did division wrong; must fix up
- ++result.quot;
- result.rem -= denom;
- }
-
- return result;
-}
-
-// 7.8.2.3 The strtoimax and strtoumax functions
-#define strtoimax _strtoi64
-#define strtoumax _strtoui64
-
-// 7.8.2.4 The wcstoimax and wcstoumax functions
-#define wcstoimax _wcstoi64
-#define wcstoumax _wcstoui64
-
-
-#endif // _MSC_INTTYPES_H_ ] \ No newline at end of file
diff --git a/numpy/random/src/common/stdint.h b/numpy/random/src/common/stdint.h
deleted file mode 100644
index 710de1570..000000000
--- a/numpy/random/src/common/stdint.h
+++ /dev/null
@@ -1,258 +0,0 @@
-// ISO C9x compliant stdint.h for Microsoft Visual Studio
-// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
-//
-// Copyright (c) 2006-2013 Alexander Chemeris
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the product nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef _MSC_VER // [
-#error "Use this header only with Microsoft Visual C++ compilers!"
-#endif // _MSC_VER ]
-
-#ifndef _MSC_STDINT_H_ // [
-#define _MSC_STDINT_H_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-#if _MSC_VER >= 1600 // [
-#include <stdint.h>
-#else // ] _MSC_VER >= 1600 [
-
-#include <limits.h>
-
-// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
-// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
-// or compiler give many errors like this:
-// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include <wchar.h>
-#ifdef __cplusplus
-}
-#endif
-
-// Define _W64 macros to mark types changing their size, like intptr_t.
-#ifndef _W64
-#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
-#define _W64 __w64
-#else
-#define _W64
-#endif
-#endif
-
-// 7.18.1 Integer types
-
-// 7.18.1.1 Exact-width integer types
-
-// Visual Studio 6 and Embedded Visual C++ 4 doesn't
-// realize that, e.g. char has the same size as __int8
-// so we give up on __intX for them.
-#if (_MSC_VER < 1300)
-typedef signed char int8_t;
-typedef signed short int16_t;
-typedef signed int int32_t;
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned int uint32_t;
-#else
-typedef signed __int8 int8_t;
-typedef signed __int16 int16_t;
-typedef signed __int32 int32_t;
-typedef unsigned __int8 uint8_t;
-typedef unsigned __int16 uint16_t;
-typedef unsigned __int32 uint32_t;
-#endif
-typedef signed __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-
-// 7.18.1.2 Minimum-width integer types
-typedef int8_t int_least8_t;
-typedef int16_t int_least16_t;
-typedef int32_t int_least32_t;
-typedef int64_t int_least64_t;
-typedef uint8_t uint_least8_t;
-typedef uint16_t uint_least16_t;
-typedef uint32_t uint_least32_t;
-typedef uint64_t uint_least64_t;
-
-// 7.18.1.3 Fastest minimum-width integer types
-typedef int8_t int_fast8_t;
-typedef int16_t int_fast16_t;
-typedef int32_t int_fast32_t;
-typedef int64_t int_fast64_t;
-typedef uint8_t uint_fast8_t;
-typedef uint16_t uint_fast16_t;
-typedef uint32_t uint_fast32_t;
-typedef uint64_t uint_fast64_t;
-
-// 7.18.1.4 Integer types capable of holding object pointers
-#ifdef _WIN64 // [
-typedef signed __int64 intptr_t;
-typedef unsigned __int64 uintptr_t;
-#else // _WIN64 ][
-typedef _W64 signed int intptr_t;
-typedef _W64 unsigned int uintptr_t;
-#endif // _WIN64 ]
-
-// 7.18.1.5 Greatest-width integer types
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
-
-// 7.18.2 Limits of specified-width integer types
-
-#if !defined(__cplusplus) || \
- defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and
- // footnote 221 at page 259
-
-// 7.18.2.1 Limits of exact-width integer types
-#define INT8_MIN ((int8_t)_I8_MIN)
-#define INT8_MAX _I8_MAX
-#define INT16_MIN ((int16_t)_I16_MIN)
-#define INT16_MAX _I16_MAX
-#define INT32_MIN ((int32_t)_I32_MIN)
-#define INT32_MAX _I32_MAX
-#define INT64_MIN ((int64_t)_I64_MIN)
-#define INT64_MAX _I64_MAX
-#define UINT8_MAX _UI8_MAX
-#define UINT16_MAX _UI16_MAX
-#define UINT32_MAX _UI32_MAX
-#define UINT64_MAX _UI64_MAX
-
-// 7.18.2.2 Limits of minimum-width integer types
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-// 7.18.2.3 Limits of fastest minimum-width integer types
-#define INT_FAST8_MIN INT8_MIN
-#define INT_FAST8_MAX INT8_MAX
-#define INT_FAST16_MIN INT16_MIN
-#define INT_FAST16_MAX INT16_MAX
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST8_MAX UINT8_MAX
-#define UINT_FAST16_MAX UINT16_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-// 7.18.2.4 Limits of integer types capable of holding object pointers
-#ifdef _WIN64 // [
-#define INTPTR_MIN INT64_MIN
-#define INTPTR_MAX INT64_MAX
-#define UINTPTR_MAX UINT64_MAX
-#else // _WIN64 ][
-#define INTPTR_MIN INT32_MIN
-#define INTPTR_MAX INT32_MAX
-#define UINTPTR_MAX UINT32_MAX
-#endif // _WIN64 ]
-
-// 7.18.2.5 Limits of greatest-width integer types
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-// 7.18.3 Limits of other integer types
-
-#ifdef _WIN64 // [
-#define PTRDIFF_MIN _I64_MIN
-#define PTRDIFF_MAX _I64_MAX
-#else // _WIN64 ][
-#define PTRDIFF_MIN _I32_MIN
-#define PTRDIFF_MAX _I32_MAX
-#endif // _WIN64 ]
-
-#define SIG_ATOMIC_MIN INT_MIN
-#define SIG_ATOMIC_MAX INT_MAX
-
-#ifndef SIZE_MAX // [
-#ifdef _WIN64 // [
-#define SIZE_MAX _UI64_MAX
-#else // _WIN64 ][
-#define SIZE_MAX _UI32_MAX
-#endif // _WIN64 ]
-#endif // SIZE_MAX ]
-
-// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
-#ifndef WCHAR_MIN // [
-#define WCHAR_MIN 0
-#endif // WCHAR_MIN ]
-#ifndef WCHAR_MAX // [
-#define WCHAR_MAX _UI16_MAX
-#endif // WCHAR_MAX ]
-
-#define WINT_MIN 0
-#define WINT_MAX _UI16_MAX
-
-#endif // __STDC_LIMIT_MACROS ]
-
-// 7.18.4 Limits of other integer types
-
-#if !defined(__cplusplus) || \
- defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
-
-// 7.18.4.1 Macros for minimum-width integer constants
-
-#define INT8_C(val) val##i8
-#define INT16_C(val) val##i16
-#define INT32_C(val) val##i32
-#define INT64_C(val) val##i64
-
-#define UINT8_C(val) val##ui8
-#define UINT16_C(val) val##ui16
-#define UINT32_C(val) val##ui32
-#define UINT64_C(val) val##ui64
-
-// 7.18.4.2 Macros for greatest-width integer constants
-// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
-// Check out Issue 9 for the details.
-#ifndef INTMAX_C // [
-#define INTMAX_C INT64_C
-#endif // INTMAX_C ]
-#ifndef UINTMAX_C // [
-#define UINTMAX_C UINT64_C
-#endif // UINTMAX_C ]
-
-#endif // __STDC_CONSTANT_MACROS ]
-
-#endif // _MSC_VER >= 1600 ]
-
-#endif // _MSC_STDINT_H_ ] \ No newline at end of file
diff --git a/numpy/random/src/distributions/distributions.c b/numpy/random/src/distributions/distributions.c
index 73396a50b..789440f8b 100644
--- a/numpy/random/src/distributions/distributions.c
+++ b/numpy/random/src/distributions/distributions.c
@@ -7,110 +7,109 @@
#endif
/* Random generators for external use */
-float random_float(brng_t *brng_state) {
- return next_float(brng_state);
-}
+float random_float(bitgen_t *bitgen_state) { return next_float(bitgen_state); }
-double random_double(brng_t *brng_state) {
- return next_double(brng_state);
+double random_double(bitgen_t *bitgen_state) {
+ return next_double(bitgen_state);
}
-static NPY_INLINE double next_standard_exponential(brng_t *brng_state) {
- return -log(1.0 - next_double(brng_state));
+static NPY_INLINE double next_standard_exponential(bitgen_t *bitgen_state) {
+ return -log(1.0 - next_double(bitgen_state));
}
-double random_standard_exponential(brng_t *brng_state) {
- return next_standard_exponential(brng_state);
+double random_standard_exponential(bitgen_t *bitgen_state) {
+ return next_standard_exponential(bitgen_state);
}
-void random_standard_exponential_fill(brng_t *brng_state, npy_intp cnt,
+void random_standard_exponential_fill(bitgen_t *bitgen_state, npy_intp cnt,
double *out) {
npy_intp i;
for (i = 0; i < cnt; i++) {
- out[i] = next_standard_exponential(brng_state);
+ out[i] = next_standard_exponential(bitgen_state);
}
}
-float random_standard_exponential_f(brng_t *brng_state) {
- return -logf(1.0f - next_float(brng_state));
+float random_standard_exponential_f(bitgen_t *bitgen_state) {
+ return -logf(1.0f - next_float(bitgen_state));
}
-void random_double_fill(brng_t *brng_state, npy_intp cnt, double *out) {
+void random_double_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) {
npy_intp i;
for (i = 0; i < cnt; i++) {
- out[i] = next_double(brng_state);
+ out[i] = next_double(bitgen_state);
}
}
#if 0
-double random_gauss(brng_t *brng_state) {
- if (brng_state->has_gauss) {
- const double temp = brng_state->gauss;
- brng_state->has_gauss = false;
- brng_state->gauss = 0.0;
+double random_gauss(bitgen_t *bitgen_state) {
+ if (bitgen_state->has_gauss) {
+ const double temp = bitgen_state->gauss;
+ bitgen_state->has_gauss = false;
+ bitgen_state->gauss = 0.0;
return temp;
} else {
double f, x1, x2, r2;
do {
- x1 = 2.0 * next_double(brng_state) - 1.0;
- x2 = 2.0 * next_double(brng_state) - 1.0;
+ x1 = 2.0 * next_double(bitgen_state) - 1.0;
+ x2 = 2.0 * next_double(bitgen_state) - 1.0;
r2 = x1 * x1 + x2 * x2;
} while (r2 >= 1.0 || r2 == 0.0);
/* Polar method, a more efficient version of the Box-Muller approach. */
f = sqrt(-2.0 * log(r2) / r2);
/* Keep for next call */
- brng_state->gauss = f * x1;
- brng_state->has_gauss = true;
+ bitgen_state->gauss = f * x1;
+ bitgen_state->has_gauss = true;
return f * x2;
}
}
-float random_gauss_f(brng_t *brng_state) {
- if (brng_state->has_gauss_f) {
- const float temp = brng_state->gauss_f;
- brng_state->has_gauss_f = false;
- brng_state->gauss_f = 0.0f;
+float random_gauss_f(bitgen_t *bitgen_state) {
+ if (bitgen_state->has_gauss_f) {
+ const float temp = bitgen_state->gauss_f;
+ bitgen_state->has_gauss_f = false;
+ bitgen_state->gauss_f = 0.0f;
return temp;
} else {
float f, x1, x2, r2;
do {
- x1 = 2.0f * next_float(brng_state) - 1.0f;
- x2 = 2.0f * next_float(brng_state) - 1.0f;
+ x1 = 2.0f * next_float(bitgen_state) - 1.0f;
+ x2 = 2.0f * next_float(bitgen_state) - 1.0f;
r2 = x1 * x1 + x2 * x2;
} while (r2 >= 1.0 || r2 == 0.0);
/* Polar method, a more efficient version of the Box-Muller approach. */
f = sqrtf(-2.0f * logf(r2) / r2);
/* Keep for next call */
- brng_state->gauss_f = f * x1;
- brng_state->has_gauss_f = true;
+ bitgen_state->gauss_f = f * x1;
+ bitgen_state->has_gauss_f = true;
return f * x2;
}
}
#endif
-static NPY_INLINE double standard_exponential_zig(brng_t *brng_state);
+static NPY_INLINE double standard_exponential_zig(bitgen_t *bitgen_state);
-static double standard_exponential_zig_unlikely(brng_t *brng_state, uint8_t idx,
- double x) {
+static double standard_exponential_zig_unlikely(bitgen_t *bitgen_state,
+ uint8_t idx, double x) {
if (idx == 0) {
- return ziggurat_exp_r - log(next_double(brng_state));
- } else if ((fe_double[idx - 1] - fe_double[idx]) * next_double(brng_state) +
+ /* Switch to 1.0 - U to avoid log(0.0), see GH 13361 */
+ return ziggurat_exp_r - log(1.0 - next_double(bitgen_state));
+ } else if ((fe_double[idx - 1] - fe_double[idx]) * next_double(bitgen_state) +
fe_double[idx] <
exp(-x)) {
return x;
} else {
- return standard_exponential_zig(brng_state);
+ return standard_exponential_zig(bitgen_state);
}
}
-static NPY_INLINE double standard_exponential_zig(brng_t *brng_state) {
+static NPY_INLINE double standard_exponential_zig(bitgen_t *bitgen_state) {
uint64_t ri;
uint8_t idx;
double x;
- ri = next_uint64(brng_state);
+ ri = next_uint64(bitgen_state);
ri >>= 3;
idx = ri & 0xFF;
ri >>= 8;
@@ -118,41 +117,42 @@ static NPY_INLINE double standard_exponential_zig(brng_t *brng_state) {
if (ri < ke_double[idx]) {
return x; /* 98.9% of the time we return here 1st try */
}
- return standard_exponential_zig_unlikely(brng_state, idx, x);
+ return standard_exponential_zig_unlikely(bitgen_state, idx, x);
}
-double random_standard_exponential_zig(brng_t *brng_state) {
- return standard_exponential_zig(brng_state);
+double random_standard_exponential_zig(bitgen_t *bitgen_state) {
+ return standard_exponential_zig(bitgen_state);
}
-void random_standard_exponential_zig_fill(brng_t *brng_state, npy_intp cnt,
+void random_standard_exponential_zig_fill(bitgen_t *bitgen_state, npy_intp cnt,
double *out) {
npy_intp i;
for (i = 0; i < cnt; i++) {
- out[i] = standard_exponential_zig(brng_state);
+ out[i] = standard_exponential_zig(bitgen_state);
}
}
-static NPY_INLINE float standard_exponential_zig_f(brng_t *brng_state);
+static NPY_INLINE float standard_exponential_zig_f(bitgen_t *bitgen_state);
-static float standard_exponential_zig_unlikely_f(brng_t *brng_state,
+static float standard_exponential_zig_unlikely_f(bitgen_t *bitgen_state,
uint8_t idx, float x) {
if (idx == 0) {
- return ziggurat_exp_r_f - logf(next_float(brng_state));
- } else if ((fe_float[idx - 1] - fe_float[idx]) * next_float(brng_state) +
+ /* Switch to 1.0 - U to avoid log(0.0), see GH 13361 */
+ return ziggurat_exp_r_f - logf(1.0f - next_float(bitgen_state));
+ } else if ((fe_float[idx - 1] - fe_float[idx]) * next_float(bitgen_state) +
fe_float[idx] <
expf(-x)) {
return x;
} else {
- return standard_exponential_zig_f(brng_state);
+ return standard_exponential_zig_f(bitgen_state);
}
}
-static NPY_INLINE float standard_exponential_zig_f(brng_t *brng_state) {
+static NPY_INLINE float standard_exponential_zig_f(bitgen_t *bitgen_state) {
uint32_t ri;
uint8_t idx;
float x;
- ri = next_uint32(brng_state);
+ ri = next_uint32(bitgen_state);
ri >>= 1;
idx = ri & 0xFF;
ri >>= 8;
@@ -160,14 +160,14 @@ static NPY_INLINE float standard_exponential_zig_f(brng_t *brng_state) {
if (ri < ke_float[idx]) {
return x; /* 98.9% of the time we return here 1st try */
}
- return standard_exponential_zig_unlikely_f(brng_state, idx, x);
+ return standard_exponential_zig_unlikely_f(bitgen_state, idx, x);
}
-float random_standard_exponential_zig_f(brng_t *brng_state) {
- return standard_exponential_zig_f(brng_state);
+float random_standard_exponential_zig_f(bitgen_t *bitgen_state) {
+ return standard_exponential_zig_f(bitgen_state);
}
-static NPY_INLINE double next_gauss_zig(brng_t *brng_state) {
+static NPY_INLINE double next_gauss_zig(bitgen_t *bitgen_state) {
uint64_t r;
int sign;
int64_t rabs;
@@ -175,7 +175,7 @@ static NPY_INLINE double next_gauss_zig(brng_t *brng_state) {
double x, xx, yy;
for (;;) {
/* r = e3n52sb8 */
- r = next_uint64(brng_state);
+ r = next_uint64(bitgen_state);
idx = r & 0xff;
r >>= 8;
sign = r & 0x1;
@@ -187,32 +187,33 @@ static NPY_INLINE double next_gauss_zig(brng_t *brng_state) {
return x; /* 99.3% of the time return here */
if (idx == 0) {
for (;;) {
- xx = -ziggurat_nor_inv_r * log(next_double(brng_state));
- yy = -log(next_double(brng_state));
+ /* Switch to 1.0 - U to avoid log(0.0), see GH 13361 */
+ xx = -ziggurat_nor_inv_r * log(1.0 - next_double(bitgen_state));
+ yy = -log(1.0 - next_double(bitgen_state));
if (yy + yy > xx * xx)
return ((rabs >> 8) & 0x1) ? -(ziggurat_nor_r + xx)
: ziggurat_nor_r + xx;
}
} else {
- if (((fi_double[idx - 1] - fi_double[idx]) * next_double(brng_state) +
+ if (((fi_double[idx - 1] - fi_double[idx]) * next_double(bitgen_state) +
fi_double[idx]) < exp(-0.5 * x * x))
return x;
}
}
}
-double random_gauss_zig(brng_t *brng_state) {
- return next_gauss_zig(brng_state);
+double random_gauss_zig(bitgen_t *bitgen_state) {
+ return next_gauss_zig(bitgen_state);
}
-void random_gauss_zig_fill(brng_t *brng_state, npy_intp cnt, double *out) {
+void random_gauss_zig_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) {
npy_intp i;
for (i = 0; i < cnt; i++) {
- out[i] = next_gauss_zig(brng_state);
+ out[i] = next_gauss_zig(bitgen_state);
}
}
-float random_gauss_zig_f(brng_t *brng_state) {
+float random_gauss_zig_f(bitgen_t *bitgen_state) {
uint32_t r;
int sign;
int32_t rabs;
@@ -220,7 +221,7 @@ float random_gauss_zig_f(brng_t *brng_state) {
float x, xx, yy;
for (;;) {
/* r = n23sb8 */
- r = next_uint32(brng_state);
+ r = next_uint32(bitgen_state);
idx = r & 0xff;
sign = (r >> 8) & 0x1;
rabs = (int32_t)((r >> 9) & 0x0007fffff);
@@ -231,14 +232,15 @@ float random_gauss_zig_f(brng_t *brng_state) {
return x; /* # 99.3% of the time return here */
if (idx == 0) {
for (;;) {
- xx = -ziggurat_nor_inv_r_f * logf(next_float(brng_state));
- yy = -logf(next_float(brng_state));
+ /* Switch to 1.0 - U to avoid log(0.0), see GH 13361 */
+ xx = -ziggurat_nor_inv_r_f * logf(1.0f - next_float(bitgen_state));
+ yy = -logf(1.0f - next_float(bitgen_state));
if (yy + yy > xx * xx)
return ((rabs >> 8) & 0x1) ? -(ziggurat_nor_r_f + xx)
: ziggurat_nor_r_f + xx;
}
} else {
- if (((fi_float[idx - 1] - fi_float[idx]) * next_float(brng_state) +
+ if (((fi_float[idx - 1] - fi_float[idx]) * next_float(bitgen_state) +
fi_float[idx]) < exp(-0.5 * x * x))
return x;
}
@@ -246,16 +248,16 @@ float random_gauss_zig_f(brng_t *brng_state) {
}
/*
-static NPY_INLINE double standard_gamma(brng_t *brng_state, double shape) {
+static NPY_INLINE double standard_gamma(bitgen_t *bitgen_state, double shape) {
double b, c;
double U, V, X, Y;
if (shape == 1.0) {
- return random_standard_exponential(brng_state);
+ return random_standard_exponential(bitgen_state);
} else if (shape < 1.0) {
for (;;) {
- U = next_double(brng_state);
- V = random_standard_exponential(brng_state);
+ U = next_double(bitgen_state);
+ V = random_standard_exponential(bitgen_state);
if (U <= 1.0 - shape) {
X = pow(U, 1. / shape);
if (X <= V) {
@@ -274,12 +276,12 @@ static NPY_INLINE double standard_gamma(brng_t *brng_state, double shape) {
c = 1. / sqrt(9 * b);
for (;;) {
do {
- X = random_gauss(brng_state);
+ X = random_gauss(bitgen_state);
V = 1.0 + c * X;
} while (V <= 0.0);
V = V * V * V;
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
if (U < 1.0 - 0.0331 * (X * X) * (X * X))
return (b * V);
if (log(U) < 0.5 * X * X + b * (1. - V + log(V)))
@@ -288,16 +290,15 @@ static NPY_INLINE double standard_gamma(brng_t *brng_state, double shape) {
}
}
-static NPY_INLINE float standard_gamma_float(brng_t *brng_state, float shape) {
- float b, c;
- float U, V, X, Y;
+static NPY_INLINE float standard_gamma_float(bitgen_t *bitgen_state, float
+shape) { float b, c; float U, V, X, Y;
if (shape == 1.0f) {
- return random_standard_exponential_f(brng_state);
+ return random_standard_exponential_f(bitgen_state);
} else if (shape < 1.0f) {
for (;;) {
- U = next_float(brng_state);
- V = random_standard_exponential_f(brng_state);
+ U = next_float(bitgen_state);
+ V = random_standard_exponential_f(bitgen_state);
if (U <= 1.0f - shape) {
X = powf(U, 1.0f / shape);
if (X <= V) {
@@ -316,12 +317,12 @@ static NPY_INLINE float standard_gamma_float(brng_t *brng_state, float shape) {
c = 1.0f / sqrtf(9.0f * b);
for (;;) {
do {
- X = random_gauss_f(brng_state);
+ X = random_gauss_f(bitgen_state);
V = 1.0f + c * X;
} while (V <= 0.0f);
V = V * V * V;
- U = next_float(brng_state);
+ U = next_float(bitgen_state);
if (U < 1.0f - 0.0331f * (X * X) * (X * X))
return (b * V);
if (logf(U) < 0.5f * X * X + b * (1.0f - V + logf(V)))
@@ -331,27 +332,28 @@ static NPY_INLINE float standard_gamma_float(brng_t *brng_state, float shape) {
}
-double random_standard_gamma(brng_t *brng_state, double shape) {
- return standard_gamma(brng_state, shape);
+double random_standard_gamma(bitgen_t *bitgen_state, double shape) {
+ return standard_gamma(bitgen_state, shape);
}
-float random_standard_gamma_f(brng_t *brng_state, float shape) {
- return standard_gamma_float(brng_state, shape);
+float random_standard_gamma_f(bitgen_t *bitgen_state, float shape) {
+ return standard_gamma_float(bitgen_state, shape);
}
*/
-static NPY_INLINE double standard_gamma_zig(brng_t *brng_state, double shape) {
+static NPY_INLINE double standard_gamma_zig(bitgen_t *bitgen_state,
+ double shape) {
double b, c;
double U, V, X, Y;
if (shape == 1.0) {
- return random_standard_exponential_zig(brng_state);
+ return random_standard_exponential_zig(bitgen_state);
} else if (shape == 0.0) {
return 0.0;
} else if (shape < 1.0) {
for (;;) {
- U = next_double(brng_state);
- V = random_standard_exponential_zig(brng_state);
+ U = next_double(bitgen_state);
+ V = random_standard_exponential_zig(bitgen_state);
if (U <= 1.0 - shape) {
X = pow(U, 1. / shape);
if (X <= V) {
@@ -370,32 +372,34 @@ static NPY_INLINE double standard_gamma_zig(brng_t *brng_state, double shape) {
c = 1. / sqrt(9 * b);
for (;;) {
do {
- X = random_gauss_zig(brng_state);
+ X = random_gauss_zig(bitgen_state);
V = 1.0 + c * X;
} while (V <= 0.0);
V = V * V * V;
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
if (U < 1.0 - 0.0331 * (X * X) * (X * X))
return (b * V);
+ /* log(0.0) ok here */
if (log(U) < 0.5 * X * X + b * (1. - V + log(V)))
return (b * V);
}
}
}
-static NPY_INLINE float standard_gamma_zig_f(brng_t *brng_state, float shape) {
+static NPY_INLINE float standard_gamma_zig_f(bitgen_t *bitgen_state,
+ float shape) {
float b, c;
float U, V, X, Y;
if (shape == 1.0f) {
- return random_standard_exponential_zig_f(brng_state);
+ return random_standard_exponential_zig_f(bitgen_state);
} else if (shape == 0.0) {
return 0.0;
} else if (shape < 1.0f) {
for (;;) {
- U = next_float(brng_state);
- V = random_standard_exponential_zig_f(brng_state);
+ U = next_float(bitgen_state);
+ V = random_standard_exponential_zig_f(bitgen_state);
if (U <= 1.0f - shape) {
X = powf(U, 1.0f / shape);
if (X <= V) {
@@ -414,49 +418,50 @@ static NPY_INLINE float standard_gamma_zig_f(brng_t *brng_state, float shape) {
c = 1.0f / sqrtf(9.0f * b);
for (;;) {
do {
- X = random_gauss_zig_f(brng_state);
+ X = random_gauss_zig_f(bitgen_state);
V = 1.0f + c * X;
} while (V <= 0.0f);
V = V * V * V;
- U = next_float(brng_state);
+ U = next_float(bitgen_state);
if (U < 1.0f - 0.0331f * (X * X) * (X * X))
return (b * V);
+ /* logf(0.0) ok here */
if (logf(U) < 0.5f * X * X + b * (1.0f - V + logf(V)))
return (b * V);
}
}
}
-double random_standard_gamma_zig(brng_t *brng_state, double shape) {
- return standard_gamma_zig(brng_state, shape);
+double random_standard_gamma_zig(bitgen_t *bitgen_state, double shape) {
+ return standard_gamma_zig(bitgen_state, shape);
}
-float random_standard_gamma_zig_f(brng_t *brng_state, float shape) {
- return standard_gamma_zig_f(brng_state, shape);
+float random_standard_gamma_zig_f(bitgen_t *bitgen_state, float shape) {
+ return standard_gamma_zig_f(bitgen_state, shape);
}
-int64_t random_positive_int64(brng_t *brng_state) {
- return next_uint64(brng_state) >> 1;
+int64_t random_positive_int64(bitgen_t *bitgen_state) {
+ return next_uint64(bitgen_state) >> 1;
}
-int32_t random_positive_int32(brng_t *brng_state) {
- return next_uint32(brng_state) >> 1;
+int32_t random_positive_int32(bitgen_t *bitgen_state) {
+ return next_uint32(bitgen_state) >> 1;
}
-int64_t random_positive_int(brng_t *brng_state) {
+int64_t random_positive_int(bitgen_t *bitgen_state) {
#if ULONG_MAX <= 0xffffffffUL
- return (int64_t)(next_uint32(brng_state) >> 1);
+ return (int64_t)(next_uint32(bitgen_state) >> 1);
#else
- return (int64_t)(next_uint64(brng_state) >> 1);
+ return (int64_t)(next_uint64(bitgen_state) >> 1);
#endif
}
-uint64_t random_uint(brng_t *brng_state) {
+uint64_t random_uint(bitgen_t *bitgen_state) {
#if ULONG_MAX <= 0xffffffffUL
- return next_uint32(brng_state);
+ return next_uint32(bitgen_state);
#else
- return next_uint64(brng_state);
+ return next_uint64(bitgen_state);
#endif
}
@@ -500,47 +505,48 @@ static double loggam(double x) {
}
/*
-double random_normal(brng_t *brng_state, double loc, double scale) {
- return loc + scale * random_gauss(brng_state);
+double random_normal(bitgen_t *bitgen_state, double loc, double scale) {
+ return loc + scale * random_gauss(bitgen_state);
}
*/
-double random_normal_zig(brng_t *brng_state, double loc, double scale) {
- return loc + scale * random_gauss_zig(brng_state);
+double random_normal_zig(bitgen_t *bitgen_state, double loc, double scale) {
+ return loc + scale * random_gauss_zig(bitgen_state);
}
-double random_exponential(brng_t *brng_state, double scale) {
- return scale * standard_exponential_zig(brng_state);
+double random_exponential(bitgen_t *bitgen_state, double scale) {
+ return scale * standard_exponential_zig(bitgen_state);
}
-double random_uniform(brng_t *brng_state, double lower, double range) {
- return lower + range * next_double(brng_state);
+double random_uniform(bitgen_t *bitgen_state, double lower, double range) {
+ return lower + range * next_double(bitgen_state);
}
-double random_gamma(brng_t *brng_state, double shape, double scale) {
- return scale * random_standard_gamma_zig(brng_state, shape);
+double random_gamma(bitgen_t *bitgen_state, double shape, double scale) {
+ return scale * random_standard_gamma_zig(bitgen_state, shape);
}
-float random_gamma_float(brng_t *brng_state, float shape, float scale) {
- return scale * random_standard_gamma_zig_f(brng_state, shape);
+float random_gamma_float(bitgen_t *bitgen_state, float shape, float scale) {
+ return scale * random_standard_gamma_zig_f(bitgen_state, shape);
}
-double random_beta(brng_t *brng_state, double a, double b) {
+double random_beta(bitgen_t *bitgen_state, double a, double b) {
double Ga, Gb;
if ((a <= 1.0) && (b <= 1.0)) {
- double U, V, X, Y;
+ double U, V, X, Y, XpY;
/* Use Johnk's algorithm */
while (1) {
- U = next_double(brng_state);
- V = next_double(brng_state);
+ U = next_double(bitgen_state);
+ V = next_double(bitgen_state);
X = pow(U, 1.0 / a);
Y = pow(V, 1.0 / b);
-
- if ((X + Y) <= 1.0) {
+ XpY = X + Y;
+ /* Reject if both U and V are 0.0, which is approx 1 in 10^106 */
+ if ((XpY <= 1.0) && (XpY > 0.0)) {
if (X + Y > 0) {
- return X / (X + Y);
+ return X / XpY;
} else {
double logX = log(U) / a;
double logY = log(V) / b;
@@ -553,83 +559,94 @@ double random_beta(brng_t *brng_state, double a, double b) {
}
}
} else {
- Ga = random_standard_gamma_zig(brng_state, a);
- Gb = random_standard_gamma_zig(brng_state, b);
+ Ga = random_standard_gamma_zig(bitgen_state, a);
+ Gb = random_standard_gamma_zig(bitgen_state, b);
return Ga / (Ga + Gb);
}
}
-double random_chisquare(brng_t *brng_state, double df) {
- return 2.0 * random_standard_gamma_zig(brng_state, df / 2.0);
+double random_chisquare(bitgen_t *bitgen_state, double df) {
+ return 2.0 * random_standard_gamma_zig(bitgen_state, df / 2.0);
}
-double random_f(brng_t *brng_state, double dfnum, double dfden) {
- return ((random_chisquare(brng_state, dfnum) * dfden) /
- (random_chisquare(brng_state, dfden) * dfnum));
+double random_f(bitgen_t *bitgen_state, double dfnum, double dfden) {
+ return ((random_chisquare(bitgen_state, dfnum) * dfden) /
+ (random_chisquare(bitgen_state, dfden) * dfnum));
}
-double random_standard_cauchy(brng_t *brng_state) {
- return random_gauss_zig(brng_state) / random_gauss_zig(brng_state);
+double random_standard_cauchy(bitgen_t *bitgen_state) {
+ return random_gauss_zig(bitgen_state) / random_gauss_zig(bitgen_state);
}
-double random_pareto(brng_t *brng_state, double a) {
- return exp(standard_exponential_zig(brng_state) / a) - 1;
+double random_pareto(bitgen_t *bitgen_state, double a) {
+ return exp(standard_exponential_zig(bitgen_state) / a) - 1;
}
-double random_weibull(brng_t *brng_state, double a) {
+double random_weibull(bitgen_t *bitgen_state, double a) {
if (a == 0.0) {
return 0.0;
}
- return pow(standard_exponential_zig(brng_state), 1. / a);
+ return pow(standard_exponential_zig(bitgen_state), 1. / a);
}
-double random_power(brng_t *brng_state, double a) {
- return pow(1 - exp(-standard_exponential_zig(brng_state)), 1. / a);
+double random_power(bitgen_t *bitgen_state, double a) {
+ return pow(1 - exp(-standard_exponential_zig(bitgen_state)), 1. / a);
}
-double random_laplace(brng_t *brng_state, double loc, double scale) {
+double random_laplace(bitgen_t *bitgen_state, double loc, double scale) {
double U;
- U = next_double(brng_state);
- if (U < 0.5) {
+ U = next_double(bitgen_state);
+ if (U >= 0.5) {
+ U = loc - scale * log(2.0 - U - U);
+ } else if (U > 0.0) {
U = loc + scale * log(U + U);
} else {
- U = loc - scale * log(2.0 - U - U);
+ /* Reject U == 0.0 and call again to get next value */
+ U = random_laplace(bitgen_state, loc, scale);
}
return U;
}
-double random_gumbel(brng_t *brng_state, double loc, double scale) {
+double random_gumbel(bitgen_t *bitgen_state, double loc, double scale) {
double U;
- U = 1.0 - next_double(brng_state);
- return loc - scale * log(-log(U));
+ U = 1.0 - next_double(bitgen_state);
+ if (U < 1.0) {
+ return loc - scale * log(-log(U));
+ }
+ /* Reject U == 1.0 and call again to get next value */
+ return random_gumbel(bitgen_state, loc, scale);
}
-double random_logistic(brng_t *brng_state, double loc, double scale) {
+double random_logistic(bitgen_t *bitgen_state, double loc, double scale) {
double U;
- U = next_double(brng_state);
- return loc + scale * log(U / (1.0 - U));
+ U = next_double(bitgen_state);
+ if (U > 0.0) {
+ return loc + scale * log(U / (1.0 - U));
+ }
+ /* Reject U == 0.0 and call again to get next value */
+ return random_logistic(bitgen_state, loc, scale);
}
-double random_lognormal(brng_t *brng_state, double mean, double sigma) {
- return exp(random_normal_zig(brng_state, mean, sigma));
+double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma) {
+ return exp(random_normal_zig(bitgen_state, mean, sigma));
}
-double random_rayleigh(brng_t *brng_state, double mode) {
- return mode * sqrt(-2.0 * log(1.0 - next_double(brng_state)));
+double random_rayleigh(bitgen_t *bitgen_state, double mode) {
+ return mode * sqrt(-2.0 * log(1.0 - next_double(bitgen_state)));
}
-double random_standard_t(brng_t *brng_state, double df) {
+double random_standard_t(bitgen_t *bitgen_state, double df) {
double num, denom;
- num = random_gauss_zig(brng_state);
- denom = random_standard_gamma_zig(brng_state, df / 2);
+ num = random_gauss_zig(bitgen_state);
+ denom = random_standard_gamma_zig(bitgen_state, df / 2);
return sqrt(df / 2) * num / sqrt(denom);
}
-static int64_t random_poisson_mult(brng_t *brng_state, double lam) {
+static int64_t random_poisson_mult(bitgen_t *bitgen_state, double lam) {
int64_t X;
double prod, U, enlam;
@@ -637,7 +654,7 @@ static int64_t random_poisson_mult(brng_t *brng_state, double lam) {
X = 0;
prod = 1.0;
while (1) {
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
prod *= U;
if (prod > enlam) {
X += 1;
@@ -654,7 +671,7 @@ static int64_t random_poisson_mult(brng_t *brng_state, double lam) {
*/
#define LS2PI 0.91893853320467267
#define TWELFTH 0.083333333333333333333333
-static int64_t random_poisson_ptrs(brng_t *brng_state, double lam) {
+static int64_t random_poisson_ptrs(bitgen_t *bitgen_state, double lam) {
int64_t k;
double U, V, slam, loglam, a, b, invalpha, vr, us;
@@ -666,8 +683,8 @@ static int64_t random_poisson_ptrs(brng_t *brng_state, double lam) {
vr = 0.9277 - 3.6224 / (b - 2);
while (1) {
- U = next_double(brng_state) - 0.5;
- V = next_double(brng_state);
+ U = next_double(bitgen_state) - 0.5;
+ V = next_double(bitgen_state);
us = 0.5 - fabs(U);
k = (int64_t)floor((2 * a / us + b) * U + lam + 0.43);
if ((us >= 0.07) && (V <= vr)) {
@@ -676,6 +693,8 @@ static int64_t random_poisson_ptrs(brng_t *brng_state, double lam) {
if ((k < 0) || ((us < 0.013) && (V > us))) {
continue;
}
+ /* log(V) == log(0.0) ok here */
+ /* if U==0.0 so that us==0.0, log is ok since always returns */
if ((log(V) + log(invalpha) - log(a / (us * us) + b)) <=
(-lam + k * loglam - loggam(k + 1))) {
return k;
@@ -683,22 +702,22 @@ static int64_t random_poisson_ptrs(brng_t *brng_state, double lam) {
}
}
-int64_t random_poisson(brng_t *brng_state, double lam) {
+int64_t random_poisson(bitgen_t *bitgen_state, double lam) {
if (lam >= 10) {
- return random_poisson_ptrs(brng_state, lam);
+ return random_poisson_ptrs(bitgen_state, lam);
} else if (lam == 0) {
return 0;
} else {
- return random_poisson_mult(brng_state, lam);
+ return random_poisson_mult(bitgen_state, lam);
}
}
-int64_t random_negative_binomial(brng_t *brng_state, double n, double p) {
- double Y = random_gamma(brng_state, n, (1 - p) / p);
- return random_poisson(brng_state, Y);
+int64_t random_negative_binomial(bitgen_t *bitgen_state, double n, double p) {
+ double Y = random_gamma(bitgen_state, n, (1 - p) / p);
+ return random_poisson(bitgen_state, Y);
}
-int64_t random_binomial_btpe(brng_t *brng_state, int64_t n, double p,
+int64_t random_binomial_btpe(bitgen_t *bitgen_state, int64_t n, double p,
binomial_t *binomial) {
double r, q, fm, p1, xm, xl, xr, c, laml, lamr, p2, p3, p4;
double a, u, v, s, F, rho, t, A, nrq, x1, x2, f1, f2, z, z2, w, w2, x;
@@ -746,8 +765,8 @@ int64_t random_binomial_btpe(brng_t *brng_state, int64_t n, double p,
/* sigh ... */
Step10:
nrq = n * r * q;
- u = next_double(brng_state) * p4;
- v = next_double(brng_state);
+ u = next_double(bitgen_state) * p4;
+ v = next_double(bitgen_state);
if (u > p1)
goto Step20;
y = (int64_t)floor(xm - p1 * v + u);
@@ -767,14 +786,16 @@ Step30:
if (u > p3)
goto Step40;
y = (int64_t)floor(xl + log(v) / laml);
- if (y < 0)
+ /* Reject if v==0.0 since previous cast is undefined */
+ if ((y < 0) || (v == 0.0))
goto Step10;
v = v * (u - p2) * laml;
goto Step50;
Step40:
y = (int64_t)floor(xr - log(v) / lamr);
- if (y > n)
+ /* Reject if v==0.0 since previous cast is undefined */
+ if ((y > n) || (v == 0.0))
goto Step10;
v = v * (u - p3) * lamr;
@@ -803,6 +824,7 @@ Step52:
rho =
(k / (nrq)) * ((k * (k / 3.0 + 0.625) + 0.16666666666666666) / nrq + 0.5);
t = -k * k / (2 * nrq);
+ /* log(0.0) ok here */
A = log(v);
if (A < (t - rho))
goto Step60;
@@ -838,7 +860,7 @@ Step60:
return y;
}
-int64_t random_binomial_inversion(brng_t *brng_state, int64_t n, double p,
+int64_t random_binomial_inversion(bitgen_t *bitgen_state, int64_t n, double p,
binomial_t *binomial) {
double q, qn, np, px, U;
int64_t X, bound;
@@ -860,13 +882,13 @@ int64_t random_binomial_inversion(brng_t *brng_state, int64_t n, double p,
}
X = 0;
px = qn;
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
while (U > px) {
X++;
if (X > bound) {
X = 0;
px = qn;
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
} else {
U -= px;
px = ((n - X + 1) * p * px) / (X * q);
@@ -875,7 +897,7 @@ int64_t random_binomial_inversion(brng_t *brng_state, int64_t n, double p,
return X;
}
-int64_t random_binomial(brng_t *brng_state, double p, int64_t n,
+int64_t random_binomial(bitgen_t *bitgen_state, double p, int64_t n,
binomial_t *binomial) {
double q;
@@ -884,52 +906,53 @@ int64_t random_binomial(brng_t *brng_state, double p, int64_t n,
if (p <= 0.5) {
if (p * n <= 30.0) {
- return random_binomial_inversion(brng_state, n, p, binomial);
+ return random_binomial_inversion(bitgen_state, n, p, binomial);
} else {
- return random_binomial_btpe(brng_state, n, p, binomial);
+ return random_binomial_btpe(bitgen_state, n, p, binomial);
}
} else {
q = 1.0 - p;
if (q * n <= 30.0) {
- return n - random_binomial_inversion(brng_state, n, q, binomial);
+ return n - random_binomial_inversion(bitgen_state, n, q, binomial);
} else {
- return n - random_binomial_btpe(brng_state, n, q, binomial);
+ return n - random_binomial_btpe(bitgen_state, n, q, binomial);
}
}
}
-double random_noncentral_chisquare(brng_t *brng_state, double df, double nonc) {
- if (npy_isnan(nonc)){
+double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
+ double nonc) {
+ if (npy_isnan(nonc)) {
return NPY_NAN;
}
if (nonc == 0) {
- return random_chisquare(brng_state, df);
+ return random_chisquare(bitgen_state, df);
}
if (1 < df) {
- const double Chi2 = random_chisquare(brng_state, df - 1);
- const double n = random_gauss_zig(brng_state) + sqrt(nonc);
+ const double Chi2 = random_chisquare(bitgen_state, df - 1);
+ const double n = random_gauss_zig(bitgen_state) + sqrt(nonc);
return Chi2 + n * n;
} else {
- const int64_t i = random_poisson(brng_state, nonc / 2.0);
- return random_chisquare(brng_state, df + 2 * i);
+ const int64_t i = random_poisson(bitgen_state, nonc / 2.0);
+ return random_chisquare(bitgen_state, df + 2 * i);
}
}
-double random_noncentral_f(brng_t *brng_state, double dfnum, double dfden,
+double random_noncentral_f(bitgen_t *bitgen_state, double dfnum, double dfden,
double nonc) {
- double t = random_noncentral_chisquare(brng_state, dfnum, nonc) * dfden;
- return t / (random_chisquare(brng_state, dfden) * dfnum);
+ double t = random_noncentral_chisquare(bitgen_state, dfnum, nonc) * dfden;
+ return t / (random_chisquare(bitgen_state, dfden) * dfnum);
}
-double random_wald(brng_t *brng_state, double mean, double scale) {
+double random_wald(bitgen_t *bitgen_state, double mean, double scale) {
double U, X, Y;
double mu_2l;
mu_2l = mean / (2 * scale);
- Y = random_gauss_zig(brng_state);
+ Y = random_gauss_zig(bitgen_state);
Y = mean * Y * Y;
X = mean + mu_2l * (Y - sqrt(4 * scale * Y + Y * Y));
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
if (U <= mean / (mean + X)) {
return X;
} else {
@@ -937,16 +960,16 @@ double random_wald(brng_t *brng_state, double mean, double scale) {
}
}
-double random_vonmises(brng_t *brng_state, double mu, double kappa) {
+double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa) {
double s;
double U, V, W, Y, Z;
double result, mod;
int neg;
- if (npy_isnan(kappa)){
+ if (npy_isnan(kappa)) {
return NPY_NAN;
}
if (kappa < 1e-8) {
- return M_PI * (2 * next_double(brng_state) - 1);
+ return M_PI * (2 * next_double(bitgen_state) - 1);
} else {
/* with double precision rho is zero until 1.4e-8 */
if (kappa < 1e-5) {
@@ -962,17 +985,21 @@ double random_vonmises(brng_t *brng_state, double mu, double kappa) {
}
while (1) {
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
Z = cos(M_PI * U);
W = (1 + s * Z) / (s + Z);
Y = kappa * (s - W);
- V = next_double(brng_state);
+ V = next_double(bitgen_state);
+ /*
+ * V==0.0 is ok here since Y >= 0 always leads
+ * to accept, while Y < 0 always rejects
+ */
if ((Y * (2 - Y) - V >= 0) || (log(Y / V) + 1 - Y >= 0)) {
break;
}
}
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
result = acos(W);
if (U < 0.5) {
@@ -990,22 +1017,22 @@ double random_vonmises(brng_t *brng_state, double mu, double kappa) {
}
}
-int64_t random_logseries(brng_t *brng_state, double p) {
+int64_t random_logseries(bitgen_t *bitgen_state, double p) {
double q, r, U, V;
int64_t result;
r = log(1.0 - p);
while (1) {
- V = next_double(brng_state);
+ V = next_double(bitgen_state);
if (V >= p) {
return 1;
}
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
q = 1.0 - exp(r * U);
if (V <= q * q) {
result = (int64_t)floor(1 + log(V) / log(q));
- if (result < 1) {
+ if ((result < 1) || (V == 0.0)) {
continue;
} else {
return result;
@@ -1018,7 +1045,7 @@ int64_t random_logseries(brng_t *brng_state, double p) {
}
}
-int64_t random_geometric_search(brng_t *brng_state, double p) {
+int64_t random_geometric_search(bitgen_t *bitgen_state, double p) {
double U;
int64_t X;
double sum, prod, q;
@@ -1026,7 +1053,7 @@ int64_t random_geometric_search(brng_t *brng_state, double p) {
X = 1;
sum = prod = p;
q = 1.0 - p;
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
while (U > sum) {
prod *= q;
sum += prod;
@@ -1035,19 +1062,19 @@ int64_t random_geometric_search(brng_t *brng_state, double p) {
return X;
}
-int64_t random_geometric_inversion(brng_t *brng_state, double p) {
- return (int64_t)ceil(log(1.0 - next_double(brng_state)) / log(1.0 - p));
+int64_t random_geometric_inversion(bitgen_t *bitgen_state, double p) {
+ return (int64_t)ceil(log(1.0 - next_double(bitgen_state)) / log(1.0 - p));
}
-int64_t random_geometric(brng_t *brng_state, double p) {
+int64_t random_geometric(bitgen_t *bitgen_state, double p) {
if (p >= 0.333333333333333333333333) {
- return random_geometric_search(brng_state, p);
+ return random_geometric_search(bitgen_state, p);
} else {
- return random_geometric_inversion(brng_state, p);
+ return random_geometric_inversion(bitgen_state, p);
}
}
-int64_t random_zipf(brng_t *brng_state, double a) {
+int64_t random_zipf(bitgen_t *bitgen_state, double a) {
double am1, b;
am1 = a - 1.0;
@@ -1055,8 +1082,8 @@ int64_t random_zipf(brng_t *brng_state, double a) {
while (1) {
double T, U, V, X;
- U = 1.0 - random_double(brng_state);
- V = random_double(brng_state);
+ U = 1.0 - random_double(bitgen_state);
+ V = random_double(bitgen_state);
X = floor(pow(U, -1.0 / am1));
/*
* The real result may be above what can be represented in a signed
@@ -1075,7 +1102,7 @@ int64_t random_zipf(brng_t *brng_state, double a) {
}
}
-double random_triangular(brng_t *brng_state, double left, double mode,
+double random_triangular(bitgen_t *bitgen_state, double left, double mode,
double right) {
double base, leftbase, ratio, leftprod, rightprod;
double U;
@@ -1086,7 +1113,7 @@ double random_triangular(brng_t *brng_state, double left, double mode,
leftprod = leftbase * base;
rightprod = (right - mode) * base;
- U = next_double(brng_state);
+ U = next_double(bitgen_state);
if (U <= ratio) {
return left + sqrt(U * leftprod);
} else {
@@ -1094,8 +1121,8 @@ double random_triangular(brng_t *brng_state, double left, double mode,
}
}
-int64_t random_hypergeometric_hyp(brng_t *brng_state, int64_t good, int64_t bad,
- int64_t sample) {
+int64_t random_hypergeometric_hyp(bitgen_t *bitgen_state, int64_t good,
+ int64_t bad, int64_t sample) {
int64_t d1, k, z;
double d2, u, y;
@@ -1105,7 +1132,7 @@ int64_t random_hypergeometric_hyp(brng_t *brng_state, int64_t good, int64_t bad,
y = d2;
k = sample;
while (y > 0.0) {
- u = next_double(brng_state);
+ u = next_double(bitgen_state);
y -= (int64_t)floor(u + y / (d1 + k));
k--;
if (k == 0)
@@ -1121,7 +1148,7 @@ int64_t random_hypergeometric_hyp(brng_t *brng_state, int64_t good, int64_t bad,
/* D2 = 3 - 2*sqrt(3/e) */
#define D1 1.7155277699214135
#define D2 0.8989161620588988
-int64_t random_hypergeometric_hrua(brng_t *brng_state, int64_t good,
+int64_t random_hypergeometric_hrua(bitgen_t *bitgen_state, int64_t good,
int64_t bad, int64_t sample) {
int64_t mingoodbad, maxgoodbad, popsize, m, d9;
double d4, d5, d6, d7, d8, d10, d11;
@@ -1144,8 +1171,8 @@ int64_t random_hypergeometric_hrua(brng_t *brng_state, int64_t good,
/* 16 for 16-decimal-digit precision in D1 and D2 */
while (1) {
- X = next_double(brng_state);
- Y = next_double(brng_state);
+ X = next_double(bitgen_state);
+ Y = next_double(bitgen_state);
W = d6 + d8 * (Y - 0.5) / X;
/* fast rejection: */
@@ -1163,7 +1190,7 @@ int64_t random_hypergeometric_hrua(brng_t *brng_state, int64_t good,
/* fast rejection: */
if (X * (X - T) >= 1)
continue;
-
+ /* log(0.0) is ok here, since always accept */
if (2.0 * log(X) <= T)
break; /* acceptance */
}
@@ -1181,18 +1208,18 @@ int64_t random_hypergeometric_hrua(brng_t *brng_state, int64_t good,
#undef D1
#undef D2
-int64_t random_hypergeometric(brng_t *brng_state, int64_t good, int64_t bad,
+int64_t random_hypergeometric(bitgen_t *bitgen_state, int64_t good, int64_t bad,
int64_t sample) {
if (sample > 10) {
- return random_hypergeometric_hrua(brng_state, good, bad, sample);
+ return random_hypergeometric_hrua(bitgen_state, good, bad, sample);
} else if (sample > 0) {
- return random_hypergeometric_hyp(brng_state, good, bad, sample);
+ return random_hypergeometric_hyp(bitgen_state, good, bad, sample);
} else {
- return 0;
+ return 0;
}
}
-uint64_t random_interval(brng_t *brng_state, uint64_t max) {
+uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max) {
uint64_t mask, value;
if (max == 0) {
return 0;
@@ -1210,15 +1237,16 @@ uint64_t random_interval(brng_t *brng_state, uint64_t max) {
/* Search a random value in [0..mask] <= max */
if (max <= 0xffffffffUL) {
- while ((value = (next_uint32(brng_state) & mask)) > max)
+ while ((value = (next_uint32(bitgen_state) & mask)) > max)
;
} else {
- while ((value = (next_uint64(brng_state) & mask)) > max)
+ while ((value = (next_uint64(bitgen_state) & mask)) > max)
;
}
return value;
}
+/* Bounded generators */
static NPY_INLINE uint64_t gen_mask(uint64_t max) {
uint64_t mask = max;
mask |= mask >> 1;
@@ -1231,10 +1259,10 @@ static NPY_INLINE uint64_t gen_mask(uint64_t max) {
}
/* Generate 16 bit random numbers using a 32 bit buffer. */
-static NPY_INLINE uint16_t buffered_uint16(brng_t *brng_state, int *bcnt,
+static NPY_INLINE uint16_t buffered_uint16(bitgen_t *bitgen_state, int *bcnt,
uint32_t *buf) {
if (!(bcnt[0])) {
- buf[0] = next_uint32(brng_state);
+ buf[0] = next_uint32(bitgen_state);
bcnt[0] = 1;
} else {
buf[0] >>= 16;
@@ -1245,10 +1273,10 @@ static NPY_INLINE uint16_t buffered_uint16(brng_t *brng_state, int *bcnt,
}
/* Generate 8 bit random numbers using a 32 bit buffer. */
-static NPY_INLINE uint8_t buffered_uint8(brng_t *brng_state, int *bcnt,
+static NPY_INLINE uint8_t buffered_uint8(bitgen_t *bitgen_state, int *bcnt,
uint32_t *buf) {
if (!(bcnt[0])) {
- buf[0] = next_uint32(brng_state);
+ buf[0] = next_uint32(bitgen_state);
bcnt[0] = 3;
} else {
buf[0] >>= 8;
@@ -1259,11 +1287,11 @@ static NPY_INLINE uint8_t buffered_uint8(brng_t *brng_state, int *bcnt,
}
/* Static `masked rejection` function called by random_bounded_uint64(...) */
-static NPY_INLINE uint64_t bounded_masked_uint64(brng_t *brng_state,
+static NPY_INLINE uint64_t bounded_masked_uint64(bitgen_t *bitgen_state,
uint64_t rng, uint64_t mask) {
uint64_t val;
- while ((val = (next_uint64(brng_state) & mask)) > rng)
+ while ((val = (next_uint64(bitgen_state) & mask)) > rng)
;
return val;
@@ -1271,8 +1299,9 @@ static NPY_INLINE uint64_t bounded_masked_uint64(brng_t *brng_state,
/* Static `masked rejection` function called by
* random_buffered_bounded_uint32(...) */
-static NPY_INLINE uint32_t buffered_bounded_masked_uint32(
- brng_t *brng_state, uint32_t rng, uint32_t mask, int *bcnt, uint32_t *buf) {
+static NPY_INLINE uint32_t
+buffered_bounded_masked_uint32(bitgen_t *bitgen_state, uint32_t rng,
+ uint32_t mask, int *bcnt, uint32_t *buf) {
/*
* The buffer and buffer count are not used here but are included to allow
* this function to be templated with the similar uint8 and uint16
@@ -1281,7 +1310,7 @@ static NPY_INLINE uint32_t buffered_bounded_masked_uint32(
uint32_t val;
- while ((val = (next_uint32(brng_state) & mask)) > rng)
+ while ((val = (next_uint32(bitgen_state) & mask)) > rng)
;
return val;
@@ -1289,11 +1318,12 @@ static NPY_INLINE uint32_t buffered_bounded_masked_uint32(
/* Static `masked rejection` function called by
* random_buffered_bounded_uint16(...) */
-static NPY_INLINE uint16_t buffered_bounded_masked_uint16(
- brng_t *brng_state, uint16_t rng, uint16_t mask, int *bcnt, uint32_t *buf) {
+static NPY_INLINE uint16_t
+buffered_bounded_masked_uint16(bitgen_t *bitgen_state, uint16_t rng,
+ uint16_t mask, int *bcnt, uint32_t *buf) {
uint16_t val;
- while ((val = (buffered_uint16(brng_state, bcnt, buf) & mask)) > rng)
+ while ((val = (buffered_uint16(bitgen_state, bcnt, buf) & mask)) > rng)
;
return val;
@@ -1301,20 +1331,36 @@ static NPY_INLINE uint16_t buffered_bounded_masked_uint16(
/* Static `masked rejection` function called by
* random_buffered_bounded_uint8(...) */
-static NPY_INLINE uint8_t buffered_bounded_masked_uint8(brng_t *brng_state,
+static NPY_INLINE uint8_t buffered_bounded_masked_uint8(bitgen_t *bitgen_state,
uint8_t rng,
uint8_t mask, int *bcnt,
uint32_t *buf) {
uint8_t val;
- while ((val = (buffered_uint8(brng_state, bcnt, buf) & mask)) > rng)
+ while ((val = (buffered_uint8(bitgen_state, bcnt, buf) & mask)) > rng)
;
return val;
}
+static NPY_INLINE npy_bool buffered_bounded_bool(bitgen_t *bitgen_state,
+ npy_bool off, npy_bool rng,
+ npy_bool mask, int *bcnt,
+ uint32_t *buf) {
+ if (rng == 0)
+ return off;
+ if (!(bcnt[0])) {
+ buf[0] = next_uint32(bitgen_state);
+ bcnt[0] = 31;
+ } else {
+ buf[0] >>= 1;
+ bcnt[0] -= 1;
+ }
+ return (buf[0] & 0x00000001UL) != 0;
+}
+
/* Static `Lemire rejection` function called by random_bounded_uint64(...) */
-static NPY_INLINE uint64_t bounded_lemire_uint64(brng_t *brng_state,
+static NPY_INLINE uint64_t bounded_lemire_uint64(bitgen_t *bitgen_state,
uint64_t rng) {
/*
* Uses Lemire's algorithm - https://arxiv.org/abs/1805.10941
@@ -1331,7 +1377,7 @@ static NPY_INLINE uint64_t bounded_lemire_uint64(brng_t *brng_state,
uint64_t leftover;
/* Generate a scaled random number. */
- m = ((__uint128_t)next_uint64(brng_state)) * rng_excl;
+ m = ((__uint128_t)next_uint64(bitgen_state)) * rng_excl;
/* Rejection sampling to remove any bias. */
leftover = m & 0xFFFFFFFFFFFFFFFFULL;
@@ -1344,7 +1390,7 @@ static NPY_INLINE uint64_t bounded_lemire_uint64(brng_t *brng_state,
* rng_excl; */
while (leftover < threshold) {
- m = ((__uint128_t)next_uint64(brng_state)) * rng_excl;
+ m = ((__uint128_t)next_uint64(bitgen_state)) * rng_excl;
leftover = m & 0xFFFFFFFFFFFFFFFFULL;
}
}
@@ -1357,7 +1403,7 @@ static NPY_INLINE uint64_t bounded_lemire_uint64(brng_t *brng_state,
uint64_t x;
uint64_t leftover;
- x = next_uint64(brng_state);
+ x = next_uint64(bitgen_state);
/* Rejection sampling to remove any bias. */
leftover = x * rng_excl; /* The lower 64-bits of the mult. */
@@ -1370,7 +1416,7 @@ static NPY_INLINE uint64_t bounded_lemire_uint64(brng_t *brng_state,
* rng_excl; */
while (leftover < threshold) {
- x = next_uint64(brng_state);
+ x = next_uint64(bitgen_state);
leftover = x * rng_excl;
}
}
@@ -1403,10 +1449,8 @@ static NPY_INLINE uint64_t bounded_lemire_uint64(brng_t *brng_state,
/* Static `Lemire rejection` function called by
* random_buffered_bounded_uint32(...) */
-static NPY_INLINE uint32_t buffered_bounded_lemire_uint32(brng_t *brng_state,
- uint32_t rng,
- int *bcnt,
- uint32_t *buf) {
+static NPY_INLINE uint32_t buffered_bounded_lemire_uint32(
+ bitgen_t *bitgen_state, uint32_t rng, int *bcnt, uint32_t *buf) {
/*
* Uses Lemire's algorithm - https://arxiv.org/abs/1805.10941
*
@@ -1423,7 +1467,7 @@ static NPY_INLINE uint32_t buffered_bounded_lemire_uint32(brng_t *brng_state,
uint32_t leftover;
/* Generate a scaled random number. */
- m = ((uint64_t)next_uint32(brng_state)) * rng_excl;
+ m = ((uint64_t)next_uint32(bitgen_state)) * rng_excl;
/* Rejection sampling to remove any bias */
leftover = m & 0xFFFFFFFFUL;
@@ -1434,7 +1478,7 @@ static NPY_INLINE uint32_t buffered_bounded_lemire_uint32(brng_t *brng_state,
/* Same as: threshold=((uint64_t)(0x100000000ULL - rng_excl)) % rng_excl; */
while (leftover < threshold) {
- m = ((uint64_t)next_uint32(brng_state)) * rng_excl;
+ m = ((uint64_t)next_uint32(bitgen_state)) * rng_excl;
leftover = m & 0xFFFFFFFFUL;
}
}
@@ -1444,10 +1488,8 @@ static NPY_INLINE uint32_t buffered_bounded_lemire_uint32(brng_t *brng_state,
/* Static `Lemire rejection` function called by
* random_buffered_bounded_uint16(...) */
-static NPY_INLINE uint16_t buffered_bounded_lemire_uint16(brng_t *brng_state,
- uint16_t rng,
- int *bcnt,
- uint32_t *buf) {
+static NPY_INLINE uint16_t buffered_bounded_lemire_uint16(
+ bitgen_t *bitgen_state, uint16_t rng, int *bcnt, uint32_t *buf) {
/*
* Uses Lemire's algorithm - https://arxiv.org/abs/1805.10941
*
@@ -1460,7 +1502,7 @@ static NPY_INLINE uint16_t buffered_bounded_lemire_uint16(brng_t *brng_state,
uint16_t leftover;
/* Generate a scaled random number. */
- m = ((uint32_t)buffered_uint16(brng_state, bcnt, buf)) * rng_excl;
+ m = ((uint32_t)buffered_uint16(bitgen_state, bcnt, buf)) * rng_excl;
/* Rejection sampling to remove any bias */
leftover = m & 0xFFFFUL;
@@ -1471,7 +1513,7 @@ static NPY_INLINE uint16_t buffered_bounded_lemire_uint16(brng_t *brng_state,
/* Same as: threshold=((uint32_t)(0x10000ULL - rng_excl)) % rng_excl; */
while (leftover < threshold) {
- m = ((uint32_t)buffered_uint16(brng_state, bcnt, buf)) * rng_excl;
+ m = ((uint32_t)buffered_uint16(bitgen_state, bcnt, buf)) * rng_excl;
leftover = m & 0xFFFFUL;
}
}
@@ -1481,7 +1523,7 @@ static NPY_INLINE uint16_t buffered_bounded_lemire_uint16(brng_t *brng_state,
/* Static `Lemire rejection` function called by
* random_buffered_bounded_uint8(...) */
-static NPY_INLINE uint8_t buffered_bounded_lemire_uint8(brng_t *brng_state,
+static NPY_INLINE uint8_t buffered_bounded_lemire_uint8(bitgen_t *bitgen_state,
uint8_t rng, int *bcnt,
uint32_t *buf) {
/*
@@ -1496,7 +1538,7 @@ static NPY_INLINE uint8_t buffered_bounded_lemire_uint8(brng_t *brng_state,
uint8_t leftover;
/* Generate a scaled random number. */
- m = ((uint16_t)buffered_uint8(brng_state, bcnt, buf)) * rng_excl;
+ m = ((uint16_t)buffered_uint8(bitgen_state, bcnt, buf)) * rng_excl;
/* Rejection sampling to remove any bias */
leftover = m & 0xFFUL;
@@ -1507,7 +1549,7 @@ static NPY_INLINE uint8_t buffered_bounded_lemire_uint8(brng_t *brng_state,
/* Same as: threshold=((uint16_t)(0x100ULL - rng_excl)) % rng_excl; */
while (leftover < threshold) {
- m = ((uint16_t)buffered_uint8(brng_state, bcnt, buf)) * rng_excl;
+ m = ((uint16_t)buffered_uint8(bitgen_state, bcnt, buf)) * rng_excl;
leftover = m & 0xFFUL;
}
}
@@ -1519,26 +1561,27 @@ static NPY_INLINE uint8_t buffered_bounded_lemire_uint8(brng_t *brng_state,
* Returns a single random npy_uint64 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-uint64_t random_bounded_uint64(brng_t *brng_state, uint64_t off, uint64_t rng,
- uint64_t mask, bool use_masked) {
+uint64_t random_bounded_uint64(bitgen_t *bitgen_state, uint64_t off,
+ uint64_t rng, uint64_t mask, bool use_masked) {
if (rng == 0) {
return off;
} else if (rng < 0xFFFFFFFFUL) {
/* Call 32-bit generator if range in 32-bit. */
if (use_masked) {
- return off +
- buffered_bounded_masked_uint32(brng_state, rng, mask, NULL, NULL);
+ return off + buffered_bounded_masked_uint32(bitgen_state, rng, mask, NULL,
+ NULL);
} else {
- return off + buffered_bounded_lemire_uint32(brng_state, rng, NULL, NULL);
+ return off +
+ buffered_bounded_lemire_uint32(bitgen_state, rng, NULL, NULL);
}
} else if (rng == 0xFFFFFFFFFFFFFFFFULL) {
/* Lemire64 doesn't support inclusive rng = 0xFFFFFFFFFFFFFFFF. */
- return off + next_uint64(brng_state);
+ return off + next_uint64(bitgen_state);
} else {
if (use_masked) {
- return off + bounded_masked_uint64(brng_state, rng, mask);
+ return off + bounded_masked_uint64(bitgen_state, rng, mask);
} else {
- return off + bounded_lemire_uint64(brng_state, rng);
+ return off + bounded_lemire_uint64(bitgen_state, rng);
}
}
}
@@ -1547,7 +1590,7 @@ uint64_t random_bounded_uint64(brng_t *brng_state, uint64_t off, uint64_t rng,
* Returns a single random npy_uint64 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-uint32_t random_buffered_bounded_uint32(brng_t *brng_state, uint32_t off,
+uint32_t random_buffered_bounded_uint32(bitgen_t *bitgen_state, uint32_t off,
uint32_t rng, uint32_t mask,
bool use_masked, int *bcnt,
uint32_t *buf) {
@@ -1559,13 +1602,13 @@ uint32_t random_buffered_bounded_uint32(brng_t *brng_state, uint32_t off,
return off;
} else if (rng == 0xFFFFFFFFUL) {
/* Lemire32 doesn't support inclusive rng = 0xFFFFFFFF. */
- return off + next_uint32(brng_state);
+ return off + next_uint32(bitgen_state);
} else {
if (use_masked) {
return off +
- buffered_bounded_masked_uint32(brng_state, rng, mask, bcnt, buf);
+ buffered_bounded_masked_uint32(bitgen_state, rng, mask, bcnt, buf);
} else {
- return off + buffered_bounded_lemire_uint32(brng_state, rng, bcnt, buf);
+ return off + buffered_bounded_lemire_uint32(bitgen_state, rng, bcnt, buf);
}
}
}
@@ -1574,7 +1617,7 @@ uint32_t random_buffered_bounded_uint32(brng_t *brng_state, uint32_t off,
* Returns a single random npy_uint16 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-uint16_t random_buffered_bounded_uint16(brng_t *brng_state, uint16_t off,
+uint16_t random_buffered_bounded_uint16(bitgen_t *bitgen_state, uint16_t off,
uint16_t rng, uint16_t mask,
bool use_masked, int *bcnt,
uint32_t *buf) {
@@ -1582,13 +1625,13 @@ uint16_t random_buffered_bounded_uint16(brng_t *brng_state, uint16_t off,
return off;
} else if (rng == 0xFFFFUL) {
/* Lemire16 doesn't support inclusive rng = 0xFFFF. */
- return off + buffered_uint16(brng_state, bcnt, buf);
+ return off + buffered_uint16(bitgen_state, bcnt, buf);
} else {
if (use_masked) {
return off +
- buffered_bounded_masked_uint16(brng_state, rng, mask, bcnt, buf);
+ buffered_bounded_masked_uint16(bitgen_state, rng, mask, bcnt, buf);
} else {
- return off + buffered_bounded_lemire_uint16(brng_state, rng, bcnt, buf);
+ return off + buffered_bounded_lemire_uint16(bitgen_state, rng, bcnt, buf);
}
}
}
@@ -1597,7 +1640,7 @@ uint16_t random_buffered_bounded_uint16(brng_t *brng_state, uint16_t off,
* Returns a single random npy_uint8 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-uint8_t random_buffered_bounded_uint8(brng_t *brng_state, uint8_t off,
+uint8_t random_buffered_bounded_uint8(bitgen_t *bitgen_state, uint8_t off,
uint8_t rng, uint8_t mask,
bool use_masked, int *bcnt,
uint32_t *buf) {
@@ -1605,46 +1648,31 @@ uint8_t random_buffered_bounded_uint8(brng_t *brng_state, uint8_t off,
return off;
} else if (rng == 0xFFUL) {
/* Lemire8 doesn't support inclusive rng = 0xFF. */
- return off + buffered_uint8(brng_state, bcnt, buf);
+ return off + buffered_uint8(bitgen_state, bcnt, buf);
} else {
if (use_masked) {
return off +
- buffered_bounded_masked_uint8(brng_state, rng, mask, bcnt, buf);
+ buffered_bounded_masked_uint8(bitgen_state, rng, mask, bcnt, buf);
} else {
- return off + buffered_bounded_lemire_uint8(brng_state, rng, bcnt, buf);
+ return off + buffered_bounded_lemire_uint8(bitgen_state, rng, bcnt, buf);
}
}
}
-static NPY_INLINE npy_bool buffered_bounded_bool(brng_t *brng_state,
- npy_bool off, npy_bool rng,
- npy_bool mask, int *bcnt,
- uint32_t *buf) {
- if (rng == 0)
- return off;
- if (!(bcnt[0])) {
- buf[0] = next_uint32(brng_state);
- bcnt[0] = 31;
- } else {
- buf[0] >>= 1;
- bcnt[0] -= 1;
- }
- return (buf[0] & 0x00000001UL) != 0;
-}
-
-npy_bool random_buffered_bounded_bool(brng_t *brng_state, npy_bool off,
+npy_bool random_buffered_bounded_bool(bitgen_t *bitgen_state, npy_bool off,
npy_bool rng, npy_bool mask,
bool use_masked, int *bcnt,
uint32_t *buf) {
- return buffered_bounded_bool(brng_state, off, rng, mask, bcnt, buf);
+ return buffered_bounded_bool(bitgen_state, off, rng, mask, bcnt, buf);
}
/*
* Fills an array with cnt random npy_uint64 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-void random_bounded_uint64_fill(brng_t *brng_state, uint64_t off, uint64_t rng,
- npy_intp cnt, bool use_masked, uint64_t *out) {
+void random_bounded_uint64_fill(bitgen_t *bitgen_state, uint64_t off,
+ uint64_t rng, npy_intp cnt, bool use_masked,
+ uint64_t *out) {
npy_intp i;
if (rng == 0) {
@@ -1661,19 +1689,19 @@ void random_bounded_uint64_fill(brng_t *brng_state, uint64_t off, uint64_t rng,
uint64_t mask = gen_mask(rng);
for (i = 0; i < cnt; i++) {
- out[i] = off + buffered_bounded_masked_uint32(brng_state, rng, mask,
+ out[i] = off + buffered_bounded_masked_uint32(bitgen_state, rng, mask,
&bcnt, &buf);
}
} else {
for (i = 0; i < cnt; i++) {
- out[i] =
- off + buffered_bounded_lemire_uint32(brng_state, rng, &bcnt, &buf);
+ out[i] = off +
+ buffered_bounded_lemire_uint32(bitgen_state, rng, &bcnt, &buf);
}
}
} else if (rng == 0xFFFFFFFFFFFFFFFFULL) {
/* Lemire64 doesn't support rng = 0xFFFFFFFFFFFFFFFF. */
for (i = 0; i < cnt; i++) {
- out[i] = off + next_uint64(brng_state);
+ out[i] = off + next_uint64(bitgen_state);
}
} else {
if (use_masked) {
@@ -1681,11 +1709,11 @@ void random_bounded_uint64_fill(brng_t *brng_state, uint64_t off, uint64_t rng,
uint64_t mask = gen_mask(rng);
for (i = 0; i < cnt; i++) {
- out[i] = off + bounded_masked_uint64(brng_state, rng, mask);
+ out[i] = off + bounded_masked_uint64(bitgen_state, rng, mask);
}
} else {
for (i = 0; i < cnt; i++) {
- out[i] = off + bounded_lemire_uint64(brng_state, rng);
+ out[i] = off + bounded_lemire_uint64(bitgen_state, rng);
}
}
}
@@ -1695,8 +1723,9 @@ void random_bounded_uint64_fill(brng_t *brng_state, uint64_t off, uint64_t rng,
* Fills an array with cnt random npy_uint32 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-void random_bounded_uint32_fill(brng_t *brng_state, uint32_t off, uint32_t rng,
- npy_intp cnt, bool use_masked, uint32_t *out) {
+void random_bounded_uint32_fill(bitgen_t *bitgen_state, uint32_t off,
+ uint32_t rng, npy_intp cnt, bool use_masked,
+ uint32_t *out) {
npy_intp i;
uint32_t buf = 0;
int bcnt = 0;
@@ -1708,7 +1737,7 @@ void random_bounded_uint32_fill(brng_t *brng_state, uint32_t off, uint32_t rng,
} else if (rng == 0xFFFFFFFFUL) {
/* Lemire32 doesn't support rng = 0xFFFFFFFF. */
for (i = 0; i < cnt; i++) {
- out[i] = off + next_uint32(brng_state);
+ out[i] = off + next_uint32(bitgen_state);
}
} else {
if (use_masked) {
@@ -1716,13 +1745,13 @@ void random_bounded_uint32_fill(brng_t *brng_state, uint32_t off, uint32_t rng,
uint32_t mask = (uint32_t)gen_mask(rng);
for (i = 0; i < cnt; i++) {
- out[i] = off + buffered_bounded_masked_uint32(brng_state, rng, mask,
+ out[i] = off + buffered_bounded_masked_uint32(bitgen_state, rng, mask,
&bcnt, &buf);
}
} else {
for (i = 0; i < cnt; i++) {
- out[i] =
- off + buffered_bounded_lemire_uint32(brng_state, rng, &bcnt, &buf);
+ out[i] = off +
+ buffered_bounded_lemire_uint32(bitgen_state, rng, &bcnt, &buf);
}
}
}
@@ -1732,8 +1761,9 @@ void random_bounded_uint32_fill(brng_t *brng_state, uint32_t off, uint32_t rng,
* Fills an array with cnt random npy_uint16 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-void random_bounded_uint16_fill(brng_t *brng_state, uint16_t off, uint16_t rng,
- npy_intp cnt, bool use_masked, uint16_t *out) {
+void random_bounded_uint16_fill(bitgen_t *bitgen_state, uint16_t off,
+ uint16_t rng, npy_intp cnt, bool use_masked,
+ uint16_t *out) {
npy_intp i;
uint32_t buf = 0;
int bcnt = 0;
@@ -1745,7 +1775,7 @@ void random_bounded_uint16_fill(brng_t *brng_state, uint16_t off, uint16_t rng,
} else if (rng == 0xFFFFUL) {
/* Lemire16 doesn't support rng = 0xFFFF. */
for (i = 0; i < cnt; i++) {
- out[i] = off + buffered_uint16(brng_state, &bcnt, &buf);
+ out[i] = off + buffered_uint16(bitgen_state, &bcnt, &buf);
}
} else {
if (use_masked) {
@@ -1753,13 +1783,13 @@ void random_bounded_uint16_fill(brng_t *brng_state, uint16_t off, uint16_t rng,
uint16_t mask = (uint16_t)gen_mask(rng);
for (i = 0; i < cnt; i++) {
- out[i] = off + buffered_bounded_masked_uint16(brng_state, rng, mask,
+ out[i] = off + buffered_bounded_masked_uint16(bitgen_state, rng, mask,
&bcnt, &buf);
}
} else {
for (i = 0; i < cnt; i++) {
- out[i] =
- off + buffered_bounded_lemire_uint16(brng_state, rng, &bcnt, &buf);
+ out[i] = off +
+ buffered_bounded_lemire_uint16(bitgen_state, rng, &bcnt, &buf);
}
}
}
@@ -1769,7 +1799,7 @@ void random_bounded_uint16_fill(brng_t *brng_state, uint16_t off, uint16_t rng,
* Fills an array with cnt random npy_uint8 between off and off + rng
* inclusive. The numbers wrap if rng is sufficiently large.
*/
-void random_bounded_uint8_fill(brng_t *brng_state, uint8_t off, uint8_t rng,
+void random_bounded_uint8_fill(bitgen_t *bitgen_state, uint8_t off, uint8_t rng,
npy_intp cnt, bool use_masked, uint8_t *out) {
npy_intp i;
uint32_t buf = 0;
@@ -1782,7 +1812,7 @@ void random_bounded_uint8_fill(brng_t *brng_state, uint8_t off, uint8_t rng,
} else if (rng == 0xFFUL) {
/* Lemire8 doesn't support rng = 0xFF. */
for (i = 0; i < cnt; i++) {
- out[i] = off + buffered_uint8(brng_state, &bcnt, &buf);
+ out[i] = off + buffered_uint8(bitgen_state, &bcnt, &buf);
}
} else {
if (use_masked) {
@@ -1790,13 +1820,13 @@ void random_bounded_uint8_fill(brng_t *brng_state, uint8_t off, uint8_t rng,
uint8_t mask = (uint8_t)gen_mask(rng);
for (i = 0; i < cnt; i++) {
- out[i] = off + buffered_bounded_masked_uint8(brng_state, rng, mask,
+ out[i] = off + buffered_bounded_masked_uint8(bitgen_state, rng, mask,
&bcnt, &buf);
}
} else {
for (i = 0; i < cnt; i++) {
out[i] =
- off + buffered_bounded_lemire_uint8(brng_state, rng, &bcnt, &buf);
+ off + buffered_bounded_lemire_uint8(bitgen_state, rng, &bcnt, &buf);
}
}
}
@@ -1806,25 +1836,26 @@ void random_bounded_uint8_fill(brng_t *brng_state, uint8_t off, uint8_t rng,
* Fills an array with cnt random npy_bool between off and off + rng
* inclusive.
*/
-void random_bounded_bool_fill(brng_t *brng_state, npy_bool off, npy_bool rng,
- npy_intp cnt, bool use_masked, npy_bool *out) {
+void random_bounded_bool_fill(bitgen_t *bitgen_state, npy_bool off,
+ npy_bool rng, npy_intp cnt, bool use_masked,
+ npy_bool *out) {
npy_bool mask = 0;
npy_intp i;
uint32_t buf = 0;
int bcnt = 0;
for (i = 0; i < cnt; i++) {
- out[i] = buffered_bounded_bool(brng_state, off, rng, mask, &bcnt, &buf);
+ out[i] = buffered_bounded_bool(bitgen_state, off, rng, mask, &bcnt, &buf);
}
}
-void random_multinomial(brng_t *brng_state, int64_t n, int64_t *mnix,
+void random_multinomial(bitgen_t *bitgen_state, int64_t n, int64_t *mnix,
double *pix, npy_intp d, binomial_t *binomial) {
double remaining_p = 1.0;
npy_intp j;
int64_t dn = n;
for (j = 0; j < (d - 1); j++) {
- mnix[j] = random_binomial(brng_state, pix[j] / remaining_p, dn, binomial);
+ mnix[j] = random_binomial(bitgen_state, pix[j] / remaining_p, dn, binomial);
dn = dn - mnix[j];
if (dn <= 0) {
break;
diff --git a/numpy/random/src/distributions/distributions.h b/numpy/random/src/distributions/distributions.h
index 8ec4a83e8..d1d439d78 100644
--- a/numpy/random/src/distributions/distributions.h
+++ b/numpy/random/src/distributions/distributions.h
@@ -3,20 +3,8 @@
#pragma once
#include <stddef.h>
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/stdint.h"
-typedef int bool;
-#define false 0
-#define true 1
-#else
-#include <stdbool.h>
-#include <stdint.h>
-#endif
-#else
#include <stdbool.h>
#include <stdint.h>
-#endif
#include "Python.h"
#include "numpy/npy_common.h"
@@ -72,152 +60,152 @@ typedef struct s_binomial_t {
double p4;
} binomial_t;
-typedef struct brng {
+typedef struct bitgen {
void *state;
uint64_t (*next_uint64)(void *st);
uint32_t (*next_uint32)(void *st);
double (*next_double)(void *st);
uint64_t (*next_raw)(void *st);
-} brng_t;
+} bitgen_t;
/* Inline generators for internal use */
-static NPY_INLINE uint32_t next_uint32(brng_t *brng_state) {
- return brng_state->next_uint32(brng_state->state);
+static NPY_INLINE uint32_t next_uint32(bitgen_t *bitgen_state) {
+ return bitgen_state->next_uint32(bitgen_state->state);
}
-static NPY_INLINE uint64_t next_uint64(brng_t *brng_state) {
- return brng_state->next_uint64(brng_state->state);
+static NPY_INLINE uint64_t next_uint64(bitgen_t *bitgen_state) {
+ return bitgen_state->next_uint64(bitgen_state->state);
}
-static NPY_INLINE float next_float(brng_t *brng_state) {
- return (next_uint32(brng_state) >> 9) * (1.0f / 8388608.0f);
+static NPY_INLINE float next_float(bitgen_t *bitgen_state) {
+ return (next_uint32(bitgen_state) >> 9) * (1.0f / 8388608.0f);
}
-static NPY_INLINE double next_double(brng_t *brng_state) {
- return brng_state->next_double(brng_state->state);
+static NPY_INLINE double next_double(bitgen_t *bitgen_state) {
+ return bitgen_state->next_double(bitgen_state->state);
}
-DECLDIR float random_float(brng_t *brng_state);
-DECLDIR double random_double(brng_t *brng_state);
-DECLDIR void random_double_fill(brng_t *brng_state, npy_intp cnt, double *out);
+DECLDIR float random_float(bitgen_t *bitgen_state);
+DECLDIR double random_double(bitgen_t *bitgen_state);
+DECLDIR void random_double_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out);
-DECLDIR int64_t random_positive_int64(brng_t *brng_state);
-DECLDIR int32_t random_positive_int32(brng_t *brng_state);
-DECLDIR int64_t random_positive_int(brng_t *brng_state);
-DECLDIR uint64_t random_uint(brng_t *brng_state);
+DECLDIR int64_t random_positive_int64(bitgen_t *bitgen_state);
+DECLDIR int32_t random_positive_int32(bitgen_t *bitgen_state);
+DECLDIR int64_t random_positive_int(bitgen_t *bitgen_state);
+DECLDIR uint64_t random_uint(bitgen_t *bitgen_state);
-DECLDIR double random_standard_exponential(brng_t *brng_state);
-DECLDIR void random_standard_exponential_fill(brng_t *brng_state, npy_intp cnt,
+DECLDIR double random_standard_exponential(bitgen_t *bitgen_state);
+DECLDIR void random_standard_exponential_fill(bitgen_t *bitgen_state, npy_intp cnt,
double *out);
-DECLDIR float random_standard_exponential_f(brng_t *brng_state);
-DECLDIR double random_standard_exponential_zig(brng_t *brng_state);
-DECLDIR void random_standard_exponential_zig_fill(brng_t *brng_state,
+DECLDIR float random_standard_exponential_f(bitgen_t *bitgen_state);
+DECLDIR double random_standard_exponential_zig(bitgen_t *bitgen_state);
+DECLDIR void random_standard_exponential_zig_fill(bitgen_t *bitgen_state,
npy_intp cnt, double *out);
-DECLDIR float random_standard_exponential_zig_f(brng_t *brng_state);
+DECLDIR float random_standard_exponential_zig_f(bitgen_t *bitgen_state);
/*
-DECLDIR double random_gauss(brng_t *brng_state);
-DECLDIR float random_gauss_f(brng_t *brng_state);
+DECLDIR double random_gauss(bitgen_t *bitgen_state);
+DECLDIR float random_gauss_f(bitgen_t *bitgen_state);
*/
-DECLDIR double random_gauss_zig(brng_t *brng_state);
-DECLDIR float random_gauss_zig_f(brng_t *brng_state);
-DECLDIR void random_gauss_zig_fill(brng_t *brng_state, npy_intp cnt,
+DECLDIR double random_gauss_zig(bitgen_t *bitgen_state);
+DECLDIR float random_gauss_zig_f(bitgen_t *bitgen_state);
+DECLDIR void random_gauss_zig_fill(bitgen_t *bitgen_state, npy_intp cnt,
double *out);
/*
-DECLDIR double random_standard_gamma(brng_t *brng_state, double shape);
-DECLDIR float random_standard_gamma_f(brng_t *brng_state, float shape);
+DECLDIR double random_standard_gamma(bitgen_t *bitgen_state, double shape);
+DECLDIR float random_standard_gamma_f(bitgen_t *bitgen_state, float shape);
*/
-DECLDIR double random_standard_gamma_zig(brng_t *brng_state, double shape);
-DECLDIR float random_standard_gamma_zig_f(brng_t *brng_state, float shape);
+DECLDIR double random_standard_gamma_zig(bitgen_t *bitgen_state, double shape);
+DECLDIR float random_standard_gamma_zig_f(bitgen_t *bitgen_state, float shape);
/*
-DECLDIR double random_normal(brng_t *brng_state, double loc, double scale);
+DECLDIR double random_normal(bitgen_t *bitgen_state, double loc, double scale);
*/
-DECLDIR double random_normal_zig(brng_t *brng_state, double loc, double scale);
-
-DECLDIR double random_gamma(brng_t *brng_state, double shape, double scale);
-DECLDIR float random_gamma_float(brng_t *brng_state, float shape, float scale);
-
-DECLDIR double random_exponential(brng_t *brng_state, double scale);
-DECLDIR double random_uniform(brng_t *brng_state, double lower, double range);
-DECLDIR double random_beta(brng_t *brng_state, double a, double b);
-DECLDIR double random_chisquare(brng_t *brng_state, double df);
-DECLDIR double random_f(brng_t *brng_state, double dfnum, double dfden);
-DECLDIR double random_standard_cauchy(brng_t *brng_state);
-DECLDIR double random_pareto(brng_t *brng_state, double a);
-DECLDIR double random_weibull(brng_t *brng_state, double a);
-DECLDIR double random_power(brng_t *brng_state, double a);
-DECLDIR double random_laplace(brng_t *brng_state, double loc, double scale);
-DECLDIR double random_gumbel(brng_t *brng_state, double loc, double scale);
-DECLDIR double random_logistic(brng_t *brng_state, double loc, double scale);
-DECLDIR double random_lognormal(brng_t *brng_state, double mean, double sigma);
-DECLDIR double random_rayleigh(brng_t *brng_state, double mode);
-DECLDIR double random_standard_t(brng_t *brng_state, double df);
-DECLDIR double random_noncentral_chisquare(brng_t *brng_state, double df,
+DECLDIR double random_normal_zig(bitgen_t *bitgen_state, double loc, double scale);
+
+DECLDIR double random_gamma(bitgen_t *bitgen_state, double shape, double scale);
+DECLDIR float random_gamma_float(bitgen_t *bitgen_state, float shape, float scale);
+
+DECLDIR double random_exponential(bitgen_t *bitgen_state, double scale);
+DECLDIR double random_uniform(bitgen_t *bitgen_state, double lower, double range);
+DECLDIR double random_beta(bitgen_t *bitgen_state, double a, double b);
+DECLDIR double random_chisquare(bitgen_t *bitgen_state, double df);
+DECLDIR double random_f(bitgen_t *bitgen_state, double dfnum, double dfden);
+DECLDIR double random_standard_cauchy(bitgen_t *bitgen_state);
+DECLDIR double random_pareto(bitgen_t *bitgen_state, double a);
+DECLDIR double random_weibull(bitgen_t *bitgen_state, double a);
+DECLDIR double random_power(bitgen_t *bitgen_state, double a);
+DECLDIR double random_laplace(bitgen_t *bitgen_state, double loc, double scale);
+DECLDIR double random_gumbel(bitgen_t *bitgen_state, double loc, double scale);
+DECLDIR double random_logistic(bitgen_t *bitgen_state, double loc, double scale);
+DECLDIR double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma);
+DECLDIR double random_rayleigh(bitgen_t *bitgen_state, double mode);
+DECLDIR double random_standard_t(bitgen_t *bitgen_state, double df);
+DECLDIR double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
double nonc);
-DECLDIR double random_noncentral_f(brng_t *brng_state, double dfnum,
+DECLDIR double random_noncentral_f(bitgen_t *bitgen_state, double dfnum,
double dfden, double nonc);
-DECLDIR double random_wald(brng_t *brng_state, double mean, double scale);
-DECLDIR double random_vonmises(brng_t *brng_state, double mu, double kappa);
-DECLDIR double random_triangular(brng_t *brng_state, double left, double mode,
+DECLDIR double random_wald(bitgen_t *bitgen_state, double mean, double scale);
+DECLDIR double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa);
+DECLDIR double random_triangular(bitgen_t *bitgen_state, double left, double mode,
double right);
-DECLDIR int64_t random_poisson(brng_t *brng_state, double lam);
-DECLDIR int64_t random_negative_binomial(brng_t *brng_state, double n,
+DECLDIR int64_t random_poisson(bitgen_t *bitgen_state, double lam);
+DECLDIR int64_t random_negative_binomial(bitgen_t *bitgen_state, double n,
double p);
-DECLDIR int64_t random_binomial(brng_t *brng_state, double p, int64_t n,
+DECLDIR int64_t random_binomial(bitgen_t *bitgen_state, double p, int64_t n,
binomial_t *binomial);
-DECLDIR int64_t random_logseries(brng_t *brng_state, double p);
-DECLDIR int64_t random_geometric_search(brng_t *brng_state, double p);
-DECLDIR int64_t random_geometric_inversion(brng_t *brng_state, double p);
-DECLDIR int64_t random_geometric(brng_t *brng_state, double p);
-DECLDIR int64_t random_zipf(brng_t *brng_state, double a);
-DECLDIR int64_t random_hypergeometric(brng_t *brng_state, int64_t good,
+DECLDIR int64_t random_logseries(bitgen_t *bitgen_state, double p);
+DECLDIR int64_t random_geometric_search(bitgen_t *bitgen_state, double p);
+DECLDIR int64_t random_geometric_inversion(bitgen_t *bitgen_state, double p);
+DECLDIR int64_t random_geometric(bitgen_t *bitgen_state, double p);
+DECLDIR int64_t random_zipf(bitgen_t *bitgen_state, double a);
+DECLDIR int64_t random_hypergeometric(bitgen_t *bitgen_state, int64_t good,
int64_t bad, int64_t sample);
-DECLDIR uint64_t random_interval(brng_t *brng_state, uint64_t max);
+DECLDIR uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max);
/* Generate random uint64 numbers in closed interval [off, off + rng]. */
-DECLDIR uint64_t random_bounded_uint64(brng_t *brng_state, uint64_t off,
+DECLDIR uint64_t random_bounded_uint64(bitgen_t *bitgen_state, uint64_t off,
uint64_t rng, uint64_t mask,
bool use_masked);
/* Generate random uint32 numbers in closed interval [off, off + rng]. */
-DECLDIR uint32_t random_buffered_bounded_uint32(brng_t *brng_state,
+DECLDIR uint32_t random_buffered_bounded_uint32(bitgen_t *bitgen_state,
uint32_t off, uint32_t rng,
uint32_t mask, bool use_masked,
int *bcnt, uint32_t *buf);
-DECLDIR uint16_t random_buffered_bounded_uint16(brng_t *brng_state,
+DECLDIR uint16_t random_buffered_bounded_uint16(bitgen_t *bitgen_state,
uint16_t off, uint16_t rng,
uint16_t mask, bool use_masked,
int *bcnt, uint32_t *buf);
-DECLDIR uint8_t random_buffered_bounded_uint8(brng_t *brng_state, uint8_t off,
+DECLDIR uint8_t random_buffered_bounded_uint8(bitgen_t *bitgen_state, uint8_t off,
uint8_t rng, uint8_t mask,
bool use_masked, int *bcnt,
uint32_t *buf);
-DECLDIR npy_bool random_buffered_bounded_bool(brng_t *brng_state, npy_bool off,
+DECLDIR npy_bool random_buffered_bounded_bool(bitgen_t *bitgen_state, npy_bool off,
npy_bool rng, npy_bool mask,
bool use_masked, int *bcnt,
uint32_t *buf);
-DECLDIR void random_bounded_uint64_fill(brng_t *brng_state, uint64_t off,
+DECLDIR void random_bounded_uint64_fill(bitgen_t *bitgen_state, uint64_t off,
uint64_t rng, npy_intp cnt,
bool use_masked, uint64_t *out);
-DECLDIR void random_bounded_uint32_fill(brng_t *brng_state, uint32_t off,
+DECLDIR void random_bounded_uint32_fill(bitgen_t *bitgen_state, uint32_t off,
uint32_t rng, npy_intp cnt,
bool use_masked, uint32_t *out);
-DECLDIR void random_bounded_uint16_fill(brng_t *brng_state, uint16_t off,
+DECLDIR void random_bounded_uint16_fill(bitgen_t *bitgen_state, uint16_t off,
uint16_t rng, npy_intp cnt,
bool use_masked, uint16_t *out);
-DECLDIR void random_bounded_uint8_fill(brng_t *brng_state, uint8_t off,
+DECLDIR void random_bounded_uint8_fill(bitgen_t *bitgen_state, uint8_t off,
uint8_t rng, npy_intp cnt,
bool use_masked, uint8_t *out);
-DECLDIR void random_bounded_bool_fill(brng_t *brng_state, npy_bool off,
+DECLDIR void random_bounded_bool_fill(bitgen_t *bitgen_state, npy_bool off,
npy_bool rng, npy_intp cnt,
bool use_masked, npy_bool *out);
-DECLDIR void random_multinomial(brng_t *brng_state, int64_t n, int64_t *mnix,
+DECLDIR void random_multinomial(bitgen_t *bitgen_state, int64_t n, int64_t *mnix,
double *pix, npy_intp d, binomial_t *binomial);
#endif
diff --git a/numpy/random/src/entropy/LICENSE.md b/numpy/random/src/entropy/LICENSE.md
deleted file mode 100644
index b7276aad7..000000000
--- a/numpy/random/src/entropy/LICENSE.md
+++ /dev/null
@@ -1,25 +0,0 @@
-# ENTROPY
-
-_Parts of this module were derived from PCG_
-
-
-PCG Random Number Generation for C.
-
-Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-For additional information about the PCG random number generation scheme,
-including its license and other licensing options, visit
-
- http://www.pcg-random.org
diff --git a/numpy/random/src/entropy/entropy.c b/numpy/random/src/entropy/entropy.c
index ead4bef83..eaca37a9c 100644
--- a/numpy/random/src/entropy/entropy.c
+++ b/numpy/random/src/entropy/entropy.c
@@ -1,34 +1,3 @@
-/*
- * PCG Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
-
-/* This code provides a mechanism for getting external randomness for
- * seeding purposes. Usually, it's just a wrapper around reading
- * /dev/random.
- *
- * Alas, because not every system provides /dev/random, we need a fallback.
- * We also need to try to test whether or not to use the fallback.
- */
-
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -47,38 +16,12 @@
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
-#endif
-
-#ifndef IS_UNIX
-#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || \
- (defined(__APPLE__) && defined(__MACH__)))
-#define IS_UNIX 1
-#else
-#define IS_UNIX 0
-#endif
-#endif
-
-// If HAVE_DEV_RANDOM is set, we use that value, otherwise we guess
-#ifndef HAVE_DEV_RANDOM
-#define HAVE_DEV_RANDOM IS_UNIX
-#endif
-
-#if HAVE_DEV_RANDOM
#include <fcntl.h>
-#include <unistd.h>
#endif
-#if HAVE_DEV_RANDOM
-/* entropy_getbytes(dest, size):
- * Use /dev/random to get some external entropy for seeding purposes.
- *
- * Note:
- * If reading /dev/random fails (which ought to never happen), it returns
- * false, otherwise it returns true. If it fails, you could instead call
- * fallback_entropy_getbytes which always succeeds.
- */
-
bool entropy_getbytes(void *dest, size_t size) {
+#ifndef _WIN32
+
int fd = open("/dev/urandom", O_RDONLY);
if (fd < 0)
return false;
@@ -86,11 +29,9 @@ bool entropy_getbytes(void *dest, size_t size) {
if ((sz < 0) || ((size_t)sz < size))
return false;
return close(fd) == 0;
-}
-#endif
-#ifdef _WIN32
-bool entropy_getbytes(void *dest, size_t size) {
+#else
+
HCRYPTPROV hCryptProv;
BOOL done;
@@ -106,8 +47,8 @@ bool entropy_getbytes(void *dest, size_t size) {
}
return true;
-}
#endif
+}
/* Thomas Wang 32/64 bits integer hash function */
uint32_t entropy_hash_32(uint32_t key) {
@@ -155,7 +96,6 @@ uint32_t entropy_randombytes(void) {
bool entropy_fallback_getbytes(void *dest, size_t size) {
int hashes = (int)size;
uint32_t *hash = malloc(hashes * sizeof(uint32_t));
- // uint32_t hash[hashes];
int i;
for (i = 0; i < hashes; i++) {
hash[i] = entropy_randombytes();
diff --git a/numpy/random/src/entropy/entropy.h b/numpy/random/src/entropy/entropy.h
index 785603dd3..f00caf61d 100644
--- a/numpy/random/src/entropy/entropy.h
+++ b/numpy/random/src/entropy/entropy.h
@@ -1,43 +1,9 @@
#ifndef _RANDOMDGEN__ENTROPY_H_
#define _RANDOMDGEN__ENTROPY_H_
-/*
- * PCG Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
#include <stddef.h>
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/stdint.h"
-typedef int bool;
-#define false 0
-#define true 1
-#else
#include <stdbool.h>
#include <stdint.h>
-#endif
-#else
-#include <stdbool.h>
-#include <stdint.h>
-#endif
extern void entropy_fill(void *dest, size_t size);
diff --git a/numpy/random/src/legacy/LICENSE.md b/numpy/random/src/legacy/LICENSE.md
deleted file mode 100644
index 88b1791b2..000000000
--- a/numpy/random/src/legacy/LICENSE.md
+++ /dev/null
@@ -1,30 +0,0 @@
-Copyright (c) 2005-2017, NumPy Developers.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-* Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
-* Neither the name of the NumPy Developers nor the names of any
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/numpy/random/src/legacy/distributions-boxmuller.c b/numpy/random/src/legacy/distributions-boxmuller.c
index 5d3ba27f8..2c715799f 100644
--- a/numpy/random/src/legacy/distributions-boxmuller.c
+++ b/numpy/random/src/legacy/distributions-boxmuller.c
@@ -1,10 +1,10 @@
#include "distributions-boxmuller.h"
-static NPY_INLINE double legacy_double(aug_brng_t *aug_state) {
- return aug_state->basicrng->next_double(aug_state->basicrng->state);
+static NPY_INLINE double legacy_double(aug_bitgen_t *aug_state) {
+ return aug_state->bit_generator->next_double(aug_state->bit_generator->state);
}
-double legacy_gauss(aug_brng_t *aug_state) {
+double legacy_gauss(aug_bitgen_t *aug_state) {
if (aug_state->has_gauss) {
const double temp = aug_state->gauss;
aug_state->has_gauss = false;
@@ -28,12 +28,12 @@ double legacy_gauss(aug_brng_t *aug_state) {
}
}
-double legacy_standard_exponential(aug_brng_t *aug_state) {
+double legacy_standard_exponential(aug_bitgen_t *aug_state) {
/* We use -log(1-U) since U is [0, 1) */
return -log(1.0 - legacy_double(aug_state));
}
-double legacy_standard_gamma(aug_brng_t *aug_state, double shape) {
+double legacy_standard_gamma(aug_bitgen_t *aug_state, double shape) {
double b, c;
double U, V, X, Y;
@@ -78,30 +78,30 @@ double legacy_standard_gamma(aug_brng_t *aug_state, double shape) {
}
}
-double legacy_gamma(aug_brng_t *aug_state, double shape, double scale) {
+double legacy_gamma(aug_bitgen_t *aug_state, double shape, double scale) {
return scale * legacy_standard_gamma(aug_state, shape);
}
-double legacy_pareto(aug_brng_t *aug_state, double a) {
+double legacy_pareto(aug_bitgen_t *aug_state, double a) {
return exp(legacy_standard_exponential(aug_state) / a) - 1;
}
-double legacy_weibull(aug_brng_t *aug_state, double a) {
+double legacy_weibull(aug_bitgen_t *aug_state, double a) {
if (a == 0.0) {
return 0.0;
}
return pow(legacy_standard_exponential(aug_state), 1. / a);
}
-double legacy_power(aug_brng_t *aug_state, double a) {
+double legacy_power(aug_bitgen_t *aug_state, double a) {
return pow(1 - exp(-legacy_standard_exponential(aug_state)), 1. / a);
}
-double legacy_chisquare(aug_brng_t *aug_state, double df) {
+double legacy_chisquare(aug_bitgen_t *aug_state, double df) {
return 2.0 * legacy_standard_gamma(aug_state, df / 2.0);
}
-double legacy_noncentral_chisquare(aug_brng_t *aug_state, double df,
+double legacy_noncentral_chisquare(aug_bitgen_t *aug_state, double df,
double nonc) {
double out;
if (nonc == 0) {
@@ -112,7 +112,7 @@ double legacy_noncentral_chisquare(aug_brng_t *aug_state, double df,
const double n = legacy_gauss(aug_state) + sqrt(nonc);
return Chi2 + n * n;
} else {
- const long i = random_poisson(aug_state->basicrng, nonc / 2.0);
+ const long i = random_poisson(aug_state->bit_generator, nonc / 2.0);
out = legacy_chisquare(aug_state, df + 2 * i);
/* Insert nan guard here to avoid changing the stream */
if (npy_isnan(nonc)){
@@ -123,13 +123,13 @@ double legacy_noncentral_chisquare(aug_brng_t *aug_state, double df,
}
}
-double legacy_noncentral_f(aug_brng_t *aug_state, double dfnum, double dfden,
+double legacy_noncentral_f(aug_bitgen_t *aug_state, double dfnum, double dfden,
double nonc) {
double t = legacy_noncentral_chisquare(aug_state, dfnum, nonc) * dfden;
return t / (legacy_chisquare(aug_state, dfden) * dfnum);
}
-double legacy_wald(aug_brng_t *aug_state, double mean, double scale) {
+double legacy_wald(aug_bitgen_t *aug_state, double mean, double scale) {
double U, X, Y;
double mu_2l;
@@ -145,15 +145,15 @@ double legacy_wald(aug_brng_t *aug_state, double mean, double scale) {
}
}
-double legacy_normal(aug_brng_t *aug_state, double loc, double scale) {
+double legacy_normal(aug_bitgen_t *aug_state, double loc, double scale) {
return loc + scale * legacy_gauss(aug_state);
}
-double legacy_lognormal(aug_brng_t *aug_state, double mean, double sigma) {
+double legacy_lognormal(aug_bitgen_t *aug_state, double mean, double sigma) {
return exp(legacy_normal(aug_state, mean, sigma));
}
-double legacy_standard_t(aug_brng_t *aug_state, double df) {
+double legacy_standard_t(aug_bitgen_t *aug_state, double df) {
double num, denom;
num = legacy_gauss(aug_state);
@@ -161,16 +161,16 @@ double legacy_standard_t(aug_brng_t *aug_state, double df) {
return sqrt(df / 2) * num / sqrt(denom);
}
-int64_t legacy_negative_binomial(aug_brng_t *aug_state, double n, double p) {
+int64_t legacy_negative_binomial(aug_bitgen_t *aug_state, double n, double p) {
double Y = legacy_gamma(aug_state, n, (1 - p) / p);
- return random_poisson(aug_state->basicrng, Y);
+ return random_poisson(aug_state->bit_generator, Y);
}
-double legacy_standard_cauchy(aug_brng_t *aug_state) {
+double legacy_standard_cauchy(aug_bitgen_t *aug_state) {
return legacy_gauss(aug_state) / legacy_gauss(aug_state);
}
-double legacy_beta(aug_brng_t *aug_state, double a, double b) {
+double legacy_beta(aug_bitgen_t *aug_state, double a, double b) {
double Ga, Gb;
if ((a <= 1.0) && (b <= 1.0)) {
@@ -204,11 +204,11 @@ double legacy_beta(aug_brng_t *aug_state, double a, double b) {
}
}
-double legacy_f(aug_brng_t *aug_state, double dfnum, double dfden) {
+double legacy_f(aug_bitgen_t *aug_state, double dfnum, double dfden) {
return ((legacy_chisquare(aug_state, dfnum) * dfden) /
(legacy_chisquare(aug_state, dfden) * dfnum));
}
-double legacy_exponential(aug_brng_t *aug_state, double scale) {
+double legacy_exponential(aug_bitgen_t *aug_state, double scale) {
return scale * legacy_standard_exponential(aug_state);
}
diff --git a/numpy/random/src/legacy/distributions-boxmuller.h b/numpy/random/src/legacy/distributions-boxmuller.h
index 445686e6c..07e093b26 100644
--- a/numpy/random/src/legacy/distributions-boxmuller.h
+++ b/numpy/random/src/legacy/distributions-boxmuller.h
@@ -4,37 +4,37 @@
#include "../distributions/distributions.h"
-typedef struct aug_brng {
- brng_t *basicrng;
+typedef struct aug_bitgen {
+ bitgen_t *bit_generator;
int has_gauss;
double gauss;
-} aug_brng_t;
+} aug_bitgen_t;
-extern double legacy_gauss(aug_brng_t *aug_state);
-extern double legacy_standard_exponential(aug_brng_t *aug_state);
-extern double legacy_pareto(aug_brng_t *aug_state, double a);
-extern double legacy_weibull(aug_brng_t *aug_state, double a);
-extern double legacy_power(aug_brng_t *aug_state, double a);
-extern double legacy_gamma(aug_brng_t *aug_state, double shape, double scale);
-extern double legacy_pareto(aug_brng_t *aug_state, double a);
-extern double legacy_weibull(aug_brng_t *aug_state, double a);
-extern double legacy_chisquare(aug_brng_t *aug_state, double df);
-extern double legacy_noncentral_chisquare(aug_brng_t *aug_state, double df,
+extern double legacy_gauss(aug_bitgen_t *aug_state);
+extern double legacy_standard_exponential(aug_bitgen_t *aug_state);
+extern double legacy_pareto(aug_bitgen_t *aug_state, double a);
+extern double legacy_weibull(aug_bitgen_t *aug_state, double a);
+extern double legacy_power(aug_bitgen_t *aug_state, double a);
+extern double legacy_gamma(aug_bitgen_t *aug_state, double shape, double scale);
+extern double legacy_pareto(aug_bitgen_t *aug_state, double a);
+extern double legacy_weibull(aug_bitgen_t *aug_state, double a);
+extern double legacy_chisquare(aug_bitgen_t *aug_state, double df);
+extern double legacy_noncentral_chisquare(aug_bitgen_t *aug_state, double df,
double nonc);
-extern double legacy_noncentral_f(aug_brng_t *aug_state, double dfnum,
+extern double legacy_noncentral_f(aug_bitgen_t *aug_state, double dfnum,
double dfden, double nonc);
-extern double legacy_wald(aug_brng_t *aug_state, double mean, double scale);
-extern double legacy_lognormal(aug_brng_t *aug_state, double mean,
+extern double legacy_wald(aug_bitgen_t *aug_state, double mean, double scale);
+extern double legacy_lognormal(aug_bitgen_t *aug_state, double mean,
double sigma);
-extern double legacy_standard_t(aug_brng_t *aug_state, double df);
-extern int64_t legacy_negative_binomial(aug_brng_t *aug_state, double n,
+extern double legacy_standard_t(aug_bitgen_t *aug_state, double df);
+extern int64_t legacy_negative_binomial(aug_bitgen_t *aug_state, double n,
double p);
-extern double legacy_standard_cauchy(aug_brng_t *state);
-extern double legacy_beta(aug_brng_t *aug_state, double a, double b);
-extern double legacy_f(aug_brng_t *aug_state, double dfnum, double dfden);
-extern double legacy_normal(aug_brng_t *aug_state, double loc, double scale);
-extern double legacy_standard_gamma(aug_brng_t *aug_state, double shape);
-extern double legacy_exponential(aug_brng_t *aug_state, double scale);
+extern double legacy_standard_cauchy(aug_bitgen_t *state);
+extern double legacy_beta(aug_bitgen_t *aug_state, double a, double b);
+extern double legacy_f(aug_bitgen_t *aug_state, double dfnum, double dfden);
+extern double legacy_normal(aug_bitgen_t *aug_state, double loc, double scale);
+extern double legacy_standard_gamma(aug_bitgen_t *aug_state, double shape);
+extern double legacy_exponential(aug_bitgen_t *aug_state, double scale);
#endif
diff --git a/numpy/random/src/mt19937/mt19937.h b/numpy/random/src/mt19937/mt19937.h
index 8105329ec..1b39e0b64 100644
--- a/numpy/random/src/mt19937/mt19937.h
+++ b/numpy/random/src/mt19937/mt19937.h
@@ -1,14 +1,6 @@
#pragma once
#include <math.h>
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/stdint.h"
-#else
-#include <stdint.h>
-#endif
-#else
#include <stdint.h>
-#endif
#ifdef _WIN32
#define inline __forceinline
diff --git a/numpy/random/src/pcg32/LICENSE.md b/numpy/random/src/pcg32/LICENSE.md
deleted file mode 100644
index 3db2ac2e8..000000000
--- a/numpy/random/src/pcg32/LICENSE.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# PCG32
-
-PCG Random Number Generation for C.
-
-Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-For additional information about the PCG random number generation scheme,
-including its license and other licensing options, visit
-
- http://www.pcg-random.org
diff --git a/numpy/random/src/pcg32/pcg-advance-64.c b/numpy/random/src/pcg32/pcg-advance-64.c
deleted file mode 100644
index 8210e7565..000000000
--- a/numpy/random/src/pcg32/pcg-advance-64.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * PCG Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
-
-/*
- * This code is derived from the canonical C++ PCG implementation, which
- * has many additional features and is preferable if you can use C++ in
- * your project.
- *
- * Repetative C code is derived using C preprocessor metaprogramming
- * techniques.
- */
-
-#include "pcg_variants.h"
-
-/* Multi-step advance functions (jump-ahead, jump-back)
- *
- * The method used here is based on Brown, "Random Number Generation
- * with Arbitrary Stride,", Transactions of the American Nuclear
- * Society (Nov. 1994). The algorithm is very similar to fast
- * exponentiation.
- *
- * Even though delta is an unsigned integer, we can pass a
- * signed integer to go backwards, it just goes "the long way round".
- */
-
-uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta, uint64_t cur_mult,
- uint64_t cur_plus)
-{
- uint64_t acc_mult = 1u;
- uint64_t acc_plus = 0u;
- while (delta > 0) {
- if (delta & 1) {
- acc_mult *= cur_mult;
- acc_plus = acc_plus * cur_mult + cur_plus;
- }
- cur_plus = (cur_mult + 1) * cur_plus;
- cur_mult *= cur_mult;
- delta /= 2;
- }
- return acc_mult * state + acc_plus;
-}
-
diff --git a/numpy/random/src/pcg32/pcg32-test-data-gen.c b/numpy/random/src/pcg32/pcg32-test-data-gen.c
deleted file mode 100644
index cccaf84b9..000000000
--- a/numpy/random/src/pcg32/pcg32-test-data-gen.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Generate testing csv files
- *
- *
- * gcc pcg32-test-data-gen.c pcg32.orig.c ../splitmix64/splitmix64.c -o
- * pgc64-test-data-gen
- */
-
-#include "pcg_variants.h"
-#include <inttypes.h>
-#include <stdio.h>
-
-#define N 1000
-
-int main() {
- pcg32_random_t rng;
- uint64_t inc, seed = 0xDEADBEAF;
- inc = 0;
- int i;
- uint64_t store[N];
- pcg32_srandom_r(&rng, seed, inc);
- for (i = 0; i < N; i++) {
- store[i] = pcg32_random_r(&rng);
- }
-
- FILE *fp;
- fp = fopen("pcg32-testset-1.csv", "w");
- if (fp == NULL) {
- printf("Couldn't open file\n");
- return -1;
- }
- fprintf(fp, "seed, 0x%" PRIx64 "\n", seed);
- for (i = 0; i < N; i++) {
- fprintf(fp, "%d, 0x%" PRIx64 "\n", i, store[i]);
- if (i == 999) {
- printf("%d, 0x%" PRIx64 "\n", i, store[i]);
- }
- }
- fclose(fp);
-
- seed = 0;
- pcg32_srandom_r(&rng, seed, inc);
- for (i = 0; i < N; i++) {
- store[i] = pcg32_random_r(&rng);
- }
- fp = fopen("pcg32-testset-2.csv", "w");
- if (fp == NULL) {
- printf("Couldn't open file\n");
- return -1;
- }
- fprintf(fp, "seed, 0x%" PRIx64 "\n", seed);
- for (i = 0; i < N; i++) {
- fprintf(fp, "%d, 0x%" PRIx64 "\n", i, store[i]);
- if (i == 999) {
- printf("%d, 0x%" PRIx64 "\n", i, store[i]);
- }
- }
- fclose(fp);
-}
diff --git a/numpy/random/src/pcg32/pcg32.c b/numpy/random/src/pcg32/pcg32.c
deleted file mode 100644
index 5fbf6759f..000000000
--- a/numpy/random/src/pcg32/pcg32.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "pcg32.h"
-
-extern inline uint64_t pcg32_next64(pcg32_state *state);
-extern inline uint32_t pcg32_next32(pcg32_state *state);
-extern inline double pcg32_next_double(pcg32_state *state);
-
-uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta, uint64_t cur_mult,
- uint64_t cur_plus) {
- uint64_t acc_mult, acc_plus;
- acc_mult = 1u;
- acc_plus = 0u;
- while (delta > 0) {
- if (delta & 1) {
- acc_mult *= cur_mult;
- acc_plus = acc_plus * cur_mult + cur_plus;
- }
- cur_plus = (cur_mult + 1) * cur_plus;
- cur_mult *= cur_mult;
- delta /= 2;
- }
- return acc_mult * state + acc_plus;
-}
-
-extern void pcg32_advance_state(pcg32_state *state, uint64_t step) {
- pcg32_advance_r(state->pcg_state, step);
-}
-
-extern void pcg32_set_seed(pcg32_state *state, uint64_t seed, uint64_t inc) {
- pcg32_srandom_r(state->pcg_state, seed, inc);
-}
diff --git a/numpy/random/src/pcg32/pcg32.h b/numpy/random/src/pcg32/pcg32.h
deleted file mode 100644
index 557113d8f..000000000
--- a/numpy/random/src/pcg32/pcg32.h
+++ /dev/null
@@ -1,89 +0,0 @@
-#ifndef _RANDOMDGEN__PCG32_H_
-#define _RANDOMDGEN__PCG32_H_
-
-#ifdef _WIN32
-#ifndef _INTTYPES
-#include "../common/stdint.h"
-#endif
-#define inline __inline __forceinline
-#else
-#include <inttypes.h>
-#endif
-
-#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
-
-struct pcg_state_setseq_64 {
- uint64_t state;
- uint64_t inc;
-};
-
-static inline uint32_t pcg_rotr_32(uint32_t value, unsigned int rot) {
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm("rorl %%cl, %0" : "=r"(value) : "0"(value), "c"(rot));
- return value;
-#else
- return (value >> rot) | (value << ((-rot) & 31));
-#endif
-}
-
-static inline void pcg_setseq_64_step_r(struct pcg_state_setseq_64 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64 + rng->inc;
-}
-
-static inline uint32_t pcg_output_xsh_rr_64_32(uint64_t state) {
- return pcg_rotr_32(((state >> 18u) ^ state) >> 27u, state >> 59u);
-}
-
-static inline uint32_t
-pcg_setseq_64_xsh_rr_32_random_r(struct pcg_state_setseq_64 *rng) {
- uint64_t oldstate;
- oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-static inline void pcg_setseq_64_srandom_r(struct pcg_state_setseq_64 *rng,
- uint64_t initstate,
- uint64_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_64_step_r(rng);
- rng->state += initstate;
- pcg_setseq_64_step_r(rng);
-}
-
-extern uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta,
- uint64_t cur_mult, uint64_t cur_plus);
-
-static inline void pcg_setseq_64_advance_r(struct pcg_state_setseq_64 *rng,
- uint64_t delta) {
- rng->state = pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64,
- rng->inc);
-}
-
-typedef struct pcg_state_setseq_64 pcg32_random_t;
-#define pcg32_random_r pcg_setseq_64_xsh_rr_32_random_r
-#define pcg32_srandom_r pcg_setseq_64_srandom_r
-#define pcg32_advance_r pcg_setseq_64_advance_r
-
-typedef struct s_pcg32_state { pcg32_random_t *pcg_state; } pcg32_state;
-
-static inline uint64_t pcg32_next64(pcg32_state *state) {
- return (uint64_t)(pcg32_random_r(state->pcg_state)) << 32 |
- pcg32_random_r(state->pcg_state);
-}
-
-static inline uint32_t pcg32_next32(pcg32_state *state) {
- return pcg32_random_r(state->pcg_state);
-}
-
-static inline double pcg32_next_double(pcg32_state *state) {
- int32_t a = pcg32_random_r(state->pcg_state) >> 5,
- b = pcg32_random_r(state->pcg_state) >> 6;
- return (a * 67108864.0 + b) / 9007199254740992.0;
-}
-
-void pcg32_advance_state(pcg32_state *state, uint64_t step);
-void pcg32_set_seed(pcg32_state *state, uint64_t seed, uint64_t inc);
-
-#endif
diff --git a/numpy/random/src/pcg32/pcg_variants.h b/numpy/random/src/pcg32/pcg_variants.h
deleted file mode 100644
index 32daac1ce..000000000
--- a/numpy/random/src/pcg32/pcg_variants.h
+++ /dev/null
@@ -1,2210 +0,0 @@
-/*
- * PCG Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
-
-/*
- * This code is derived from the canonical C++ PCG implementation, which
- * has many additional features and is preferable if you can use C++ in
- * your project.
- *
- * Much of the derivation was performed mechanically. In particular, the
- * output functions were generated by compiling the C++ output functions
- * into LLVM bitcode and then transforming that using the LLVM C backend
- * (from https://github.com/draperlaboratory/llvm-cbe), and then
- * postprocessing and hand editing the output.
- *
- * Much of the remaining code was generated by C-preprocessor metaprogramming.
- */
-
-#ifndef PCG_VARIANTS_H_INCLUDED
-#define PCG_VARIANTS_H_INCLUDED 1
-
-#include <inttypes.h>
-
-#if __SIZEOF_INT128__
- typedef __uint128_t pcg128_t;
- #define PCG_128BIT_CONSTANT(high,low) \
- ((((pcg128_t)high) << 64) + low)
- #define PCG_HAS_128BIT_OPS 1
-#endif
-
-#if __GNUC_GNU_INLINE__ && !defined(__cplusplus)
- #error Nonstandard GNU inlining semantics. Compile with -std=c99 or better.
- // We could instead use macros PCG_INLINE and PCG_EXTERN_INLINE
- // but better to just reject ancient C code.
-#endif
-
-#if __cplusplus
-extern "C" {
-#endif
-
-/*
- * Rotate helper functions.
- */
-
-inline uint8_t pcg_rotr_8(uint8_t value, unsigned int rot)
-{
-/* Unfortunately, clang is kinda pathetic when it comes to properly
- * recognizing idiomatic rotate code, so for clang we actually provide
- * assembler directives (enabled with PCG_USE_INLINE_ASM). Boo, hiss.
- */
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm ("rorb %%cl, %0" : "=r" (value) : "0" (value), "c" (rot));
- return value;
-#else
- return (value >> rot) | (value << ((- rot) & 7));
-#endif
-}
-
-inline uint16_t pcg_rotr_16(uint16_t value, unsigned int rot)
-{
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm ("rorw %%cl, %0" : "=r" (value) : "0" (value), "c" (rot));
- return value;
-#else
- return (value >> rot) | (value << ((- rot) & 15));
-#endif
-}
-
-inline uint32_t pcg_rotr_32(uint32_t value, unsigned int rot)
-{
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm ("rorl %%cl, %0" : "=r" (value) : "0" (value), "c" (rot));
- return value;
-#else
- return (value >> rot) | (value << ((- rot) & 31));
-#endif
-}
-
-inline uint64_t pcg_rotr_64(uint64_t value, unsigned int rot)
-{
-#if 0 && PCG_USE_INLINE_ASM && __clang__ && __x86_64__
- // For whatever reason, clang actually *does* generate rotq by
- // itself, so we don't need this code.
- asm ("rorq %%cl, %0" : "=r" (value) : "0" (value), "c" (rot));
- return value;
-#else
- return (value >> rot) | (value << ((- rot) & 63));
-#endif
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_rotr_128(pcg128_t value, unsigned int rot)
-{
- return (value >> rot) | (value << ((- rot) & 127));
-}
-#endif
-
-/*
- * Output functions. These are the core of the PCG generation scheme.
- */
-
-// XSH RS
-
-inline uint8_t pcg_output_xsh_rs_16_8(uint16_t state)
-{
- return (uint8_t)(((state >> 7u) ^ state) >> ((state >> 14u) + 3u));
-}
-
-inline uint16_t pcg_output_xsh_rs_32_16(uint32_t state)
-{
- return (uint16_t)(((state >> 11u) ^ state) >> ((state >> 30u) + 11u));
-}
-
-inline uint32_t pcg_output_xsh_rs_64_32(uint64_t state)
-{
-
- return (uint32_t)(((state >> 22u) ^ state) >> ((state >> 61u) + 22u));
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_output_xsh_rs_128_64(pcg128_t state)
-{
- return (uint64_t)(((state >> 43u) ^ state) >> ((state >> 124u) + 45u));
-}
-#endif
-
-// XSH RR
-
-inline uint8_t pcg_output_xsh_rr_16_8(uint16_t state)
-{
- return pcg_rotr_8(((state >> 5u) ^ state) >> 5u, state >> 13u);
-}
-
-inline uint16_t pcg_output_xsh_rr_32_16(uint32_t state)
-{
- return pcg_rotr_16(((state >> 10u) ^ state) >> 12u, state >> 28u);
-}
-
-inline uint32_t pcg_output_xsh_rr_64_32(uint64_t state)
-{
- return pcg_rotr_32(((state >> 18u) ^ state) >> 27u, state >> 59u);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_output_xsh_rr_128_64(pcg128_t state)
-{
- return pcg_rotr_64(((state >> 29u) ^ state) >> 58u, state >> 122u);
-}
-#endif
-
-// RXS M XS
-
-inline uint8_t pcg_output_rxs_m_xs_8_8(uint8_t state)
-{
- uint8_t word = ((state >> ((state >> 6u) + 2u)) ^ state) * 217u;
- return (word >> 6u) ^ word;
-}
-
-inline uint16_t pcg_output_rxs_m_xs_16_16(uint16_t state)
-{
- uint16_t word = ((state >> ((state >> 13u) + 3u)) ^ state) * 62169u;
- return (word >> 11u) ^ word;
-}
-
-inline uint32_t pcg_output_rxs_m_xs_32_32(uint32_t state)
-{
- uint32_t word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
- return (word >> 22u) ^ word;
-}
-
-inline uint64_t pcg_output_rxs_m_xs_64_64(uint64_t state)
-{
- uint64_t word = ((state >> ((state >> 59u) + 5u)) ^ state)
- * 12605985483714917081ull;
- return (word >> 43u) ^ word;
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_output_rxs_m_xs_128_128(pcg128_t state)
-{
- pcg128_t word = ((state >> ((state >> 122u) + 6u)) ^ state)
- * (PCG_128BIT_CONSTANT(17766728186571221404ULL,
- 12605985483714917081ULL));
- // 327738287884841127335028083622016905945
- return (word >> 86u) ^ word;
-}
-#endif
-
-// XSL RR (only defined for >= 64 bits)
-
-inline uint32_t pcg_output_xsl_rr_64_32(uint64_t state)
-{
- return pcg_rotr_32(((uint32_t)(state >> 32u)) ^ (uint32_t)state,
- state >> 59u);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state)
-{
- return pcg_rotr_64(((uint64_t)(state >> 64u)) ^ (uint64_t)state,
- state >> 122u);
-}
-#endif
-
-// XSL RR RR (only defined for >= 64 bits)
-
-inline uint64_t pcg_output_xsl_rr_rr_64_64(uint64_t state)
-{
- uint32_t rot1 = (uint32_t)(state >> 59u);
- uint32_t high = (uint32_t)(state >> 32u);
- uint32_t low = (uint32_t)state;
- uint32_t xored = high ^ low;
- uint32_t newlow = pcg_rotr_32(xored, rot1);
- uint32_t newhigh = pcg_rotr_32(high, newlow & 31u);
- return (((uint64_t)newhigh) << 32u) | newlow;
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_output_xsl_rr_rr_128_128(pcg128_t state)
-{
- uint32_t rot1 = (uint32_t)(state >> 122u);
- uint64_t high = (uint64_t)(state >> 64u);
- uint64_t low = (uint64_t)state;
- uint64_t xored = high ^ low;
- uint64_t newlow = pcg_rotr_64(xored, rot1);
- uint64_t newhigh = pcg_rotr_64(high, newlow & 63u);
- return (((pcg128_t)newhigh) << 64u) | newlow;
-}
-#endif
-
-#define PCG_DEFAULT_MULTIPLIER_8 141U
-#define PCG_DEFAULT_MULTIPLIER_16 12829U
-#define PCG_DEFAULT_MULTIPLIER_32 747796405U
-#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
-
-#define PCG_DEFAULT_INCREMENT_8 77U
-#define PCG_DEFAULT_INCREMENT_16 47989U
-#define PCG_DEFAULT_INCREMENT_32 2891336453U
-#define PCG_DEFAULT_INCREMENT_64 1442695040888963407ULL
-
-#if PCG_HAS_128BIT_OPS
-#define PCG_DEFAULT_MULTIPLIER_128 \
- PCG_128BIT_CONSTANT(2549297995355413924ULL,4865540595714422341ULL)
-#define PCG_DEFAULT_INCREMENT_128 \
- PCG_128BIT_CONSTANT(6364136223846793005ULL,1442695040888963407ULL)
-#endif
-
-/*
- * Static initialization constants (if you can't call srandom for some
- * bizarre reason).
- */
-
-#define PCG_STATE_ONESEQ_8_INITIALIZER { 0xd7U }
-#define PCG_STATE_ONESEQ_16_INITIALIZER { 0x20dfU }
-#define PCG_STATE_ONESEQ_32_INITIALIZER { 0x46b56677U }
-#define PCG_STATE_ONESEQ_64_INITIALIZER { 0x4d595df4d0f33173ULL }
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_ONESEQ_128_INITIALIZER \
- { PCG_128BIT_CONSTANT(0xb8dc10e158a92392ULL, 0x98046df007ec0a53ULL) }
-#endif
-
-#define PCG_STATE_UNIQUE_8_INITIALIZER PCG_STATE_ONESEQ_8_INITIALIZER
-#define PCG_STATE_UNIQUE_16_INITIALIZER PCG_STATE_ONESEQ_16_INITIALIZER
-#define PCG_STATE_UNIQUE_32_INITIALIZER PCG_STATE_ONESEQ_32_INITIALIZER
-#define PCG_STATE_UNIQUE_64_INITIALIZER PCG_STATE_ONESEQ_64_INITIALIZER
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_UNIQUE_128_INITIALIZER PCG_STATE_ONESEQ_128_INITIALIZER
-#endif
-
-#define PCG_STATE_MCG_8_INITIALIZER { 0xe5U }
-#define PCG_STATE_MCG_16_INITIALIZER { 0xa5e5U }
-#define PCG_STATE_MCG_32_INITIALIZER { 0xd15ea5e5U }
-#define PCG_STATE_MCG_64_INITIALIZER { 0xcafef00dd15ea5e5ULL }
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_MCG_128_INITIALIZER \
- { PCG_128BIT_CONSTANT(0x0000000000000000ULL, 0xcafef00dd15ea5e5ULL) }
-#endif
-
-#define PCG_STATE_SETSEQ_8_INITIALIZER { 0x9bU, 0xdbU }
-#define PCG_STATE_SETSEQ_16_INITIALIZER { 0xe39bU, 0x5bdbU }
-#define PCG_STATE_SETSEQ_32_INITIALIZER { 0xec02d89bU, 0x94b95bdbU }
-#define PCG_STATE_SETSEQ_64_INITIALIZER \
- { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL }
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_SETSEQ_128_INITIALIZER \
- { PCG_128BIT_CONSTANT(0x979c9a98d8462005ULL, 0x7d3e9cb6cfe0549bULL), \
- PCG_128BIT_CONSTANT(0x0000000000000001ULL, 0xda3e39cb94b95bdbULL) }
-#endif
-
-/* Representations for the oneseq, mcg, and unique variants */
-
-struct pcg_state_8 {
- uint8_t state;
-};
-
-struct pcg_state_16 {
- uint16_t state;
-};
-
-struct pcg_state_32 {
- uint32_t state;
-};
-
-struct pcg_state_64 {
- uint64_t state;
-};
-
-#if PCG_HAS_128BIT_OPS
-struct pcg_state_128 {
- pcg128_t state;
-};
-#endif
-
-/* Representations setseq variants */
-
-struct pcg_state_setseq_8 {
- uint8_t state;
- uint8_t inc;
-};
-
-struct pcg_state_setseq_16 {
- uint16_t state;
- uint16_t inc;
-};
-
-struct pcg_state_setseq_32 {
- uint32_t state;
- uint32_t inc;
-};
-
-struct pcg_state_setseq_64 {
- uint64_t state;
- uint64_t inc;
-};
-
-#if PCG_HAS_128BIT_OPS
-struct pcg_state_setseq_128 {
- pcg128_t state;
- pcg128_t inc;
-};
-#endif
-
-/* Multi-step advance functions (jump-ahead, jump-back) */
-
-extern uint8_t pcg_advance_lcg_8(uint8_t state, uint8_t delta, uint8_t cur_mult,
- uint8_t cur_plus);
-extern uint16_t pcg_advance_lcg_16(uint16_t state, uint16_t delta,
- uint16_t cur_mult, uint16_t cur_plus);
-extern uint32_t pcg_advance_lcg_32(uint32_t state, uint32_t delta,
- uint32_t cur_mult, uint32_t cur_plus);
-extern uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta,
- uint64_t cur_mult, uint64_t cur_plus);
-
-#if PCG_HAS_128BIT_OPS
-extern pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta,
- pcg128_t cur_mult, pcg128_t cur_plus);
-#endif
-
-/* Functions to advance the underlying LCG, one version for each size and
- * each style. These functions are considered semi-private. There is rarely
- * a good reason to call them directly.
- */
-
-inline void pcg_oneseq_8_step_r(struct pcg_state_8* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8
- + PCG_DEFAULT_INCREMENT_8;
-}
-
-inline void pcg_oneseq_8_advance_r(struct pcg_state_8* rng, uint8_t delta)
-{
- rng->state = pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8,
- PCG_DEFAULT_INCREMENT_8);
-}
-
-inline void pcg_mcg_8_step_r(struct pcg_state_8* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8;
-}
-
-inline void pcg_mcg_8_advance_r(struct pcg_state_8* rng, uint8_t delta)
-{
- rng->state
- = pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8, 0u);
-}
-
-inline void pcg_unique_8_step_r(struct pcg_state_8* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8
- + (uint8_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_8_advance_r(struct pcg_state_8* rng, uint8_t delta)
-{
- rng->state = pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8,
- (uint8_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_8_step_r(struct pcg_state_setseq_8* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8 + rng->inc;
-}
-
-inline void pcg_setseq_8_advance_r(struct pcg_state_setseq_8* rng,
- uint8_t delta)
-{
- rng->state = pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8,
- rng->inc);
-}
-
-inline void pcg_oneseq_16_step_r(struct pcg_state_16* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_16
- + PCG_DEFAULT_INCREMENT_16;
-}
-
-inline void pcg_oneseq_16_advance_r(struct pcg_state_16* rng, uint16_t delta)
-{
- rng->state = pcg_advance_lcg_16(
- rng->state, delta, PCG_DEFAULT_MULTIPLIER_16, PCG_DEFAULT_INCREMENT_16);
-}
-
-inline void pcg_mcg_16_step_r(struct pcg_state_16* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_16;
-}
-
-inline void pcg_mcg_16_advance_r(struct pcg_state_16* rng, uint16_t delta)
-{
- rng->state
- = pcg_advance_lcg_16(rng->state, delta, PCG_DEFAULT_MULTIPLIER_16, 0u);
-}
-
-inline void pcg_unique_16_step_r(struct pcg_state_16* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_16
- + (uint16_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_16_advance_r(struct pcg_state_16* rng, uint16_t delta)
-{
- rng->state
- = pcg_advance_lcg_16(rng->state, delta, PCG_DEFAULT_MULTIPLIER_16,
- (uint16_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_16_step_r(struct pcg_state_setseq_16* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_16 + rng->inc;
-}
-
-inline void pcg_setseq_16_advance_r(struct pcg_state_setseq_16* rng,
- uint16_t delta)
-{
- rng->state = pcg_advance_lcg_16(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_16, rng->inc);
-}
-
-inline void pcg_oneseq_32_step_r(struct pcg_state_32* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_32
- + PCG_DEFAULT_INCREMENT_32;
-}
-
-inline void pcg_oneseq_32_advance_r(struct pcg_state_32* rng, uint32_t delta)
-{
- rng->state = pcg_advance_lcg_32(
- rng->state, delta, PCG_DEFAULT_MULTIPLIER_32, PCG_DEFAULT_INCREMENT_32);
-}
-
-inline void pcg_mcg_32_step_r(struct pcg_state_32* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_32;
-}
-
-inline void pcg_mcg_32_advance_r(struct pcg_state_32* rng, uint32_t delta)
-{
- rng->state
- = pcg_advance_lcg_32(rng->state, delta, PCG_DEFAULT_MULTIPLIER_32, 0u);
-}
-
-inline void pcg_unique_32_step_r(struct pcg_state_32* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_32
- + (uint32_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_32_advance_r(struct pcg_state_32* rng, uint32_t delta)
-{
- rng->state
- = pcg_advance_lcg_32(rng->state, delta, PCG_DEFAULT_MULTIPLIER_32,
- (uint32_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_32_step_r(struct pcg_state_setseq_32* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_32 + rng->inc;
-}
-
-inline void pcg_setseq_32_advance_r(struct pcg_state_setseq_32* rng,
- uint32_t delta)
-{
- rng->state = pcg_advance_lcg_32(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_32, rng->inc);
-}
-
-inline void pcg_oneseq_64_step_r(struct pcg_state_64* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64
- + PCG_DEFAULT_INCREMENT_64;
-}
-
-inline void pcg_oneseq_64_advance_r(struct pcg_state_64* rng, uint64_t delta)
-{
- rng->state = pcg_advance_lcg_64(
- rng->state, delta, PCG_DEFAULT_MULTIPLIER_64, PCG_DEFAULT_INCREMENT_64);
-}
-
-inline void pcg_mcg_64_step_r(struct pcg_state_64* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64;
-}
-
-inline void pcg_mcg_64_advance_r(struct pcg_state_64* rng, uint64_t delta)
-{
- rng->state
- = pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64, 0u);
-}
-
-inline void pcg_unique_64_step_r(struct pcg_state_64* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64
- + (uint64_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_64_advance_r(struct pcg_state_64* rng, uint64_t delta)
-{
- rng->state
- = pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64,
- (uint64_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_64_step_r(struct pcg_state_setseq_64* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64 + rng->inc;
-}
-
-inline void pcg_setseq_64_advance_r(struct pcg_state_setseq_64* rng,
- uint64_t delta)
-{
- rng->state = pcg_advance_lcg_64(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_64, rng->inc);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_oneseq_128_step_r(struct pcg_state_128* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128
- + PCG_DEFAULT_INCREMENT_128;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_oneseq_128_advance_r(struct pcg_state_128* rng, pcg128_t delta)
-{
- rng->state
- = pcg_advance_lcg_128(rng->state, delta, PCG_DEFAULT_MULTIPLIER_128,
- PCG_DEFAULT_INCREMENT_128);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_mcg_128_step_r(struct pcg_state_128* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_mcg_128_advance_r(struct pcg_state_128* rng, pcg128_t delta)
-{
- rng->state = pcg_advance_lcg_128(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_128, 0u);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_unique_128_step_r(struct pcg_state_128* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128
- + (pcg128_t)(((intptr_t)rng) | 1u);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_unique_128_advance_r(struct pcg_state_128* rng, pcg128_t delta)
-{
- rng->state
- = pcg_advance_lcg_128(rng->state, delta, PCG_DEFAULT_MULTIPLIER_128,
- (pcg128_t)(((intptr_t)rng) | 1u));
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_setseq_128_step_r(struct pcg_state_setseq_128* rng)
-{
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128 + rng->inc;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_setseq_128_advance_r(struct pcg_state_setseq_128* rng,
- pcg128_t delta)
-{
- rng->state = pcg_advance_lcg_128(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_128, rng->inc);
-}
-#endif
-
-/* Functions to seed the RNG state, one version for each size and each
- * style. Unlike the step functions, regular users can and should call
- * these functions.
- */
-
-inline void pcg_oneseq_8_srandom_r(struct pcg_state_8* rng, uint8_t initstate)
-{
- rng->state = 0U;
- pcg_oneseq_8_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_8_step_r(rng);
-}
-
-inline void pcg_mcg_8_srandom_r(struct pcg_state_8* rng, uint8_t initstate)
-{
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_8_srandom_r(struct pcg_state_8* rng, uint8_t initstate)
-{
- rng->state = 0U;
- pcg_unique_8_step_r(rng);
- rng->state += initstate;
- pcg_unique_8_step_r(rng);
-}
-
-inline void pcg_setseq_8_srandom_r(struct pcg_state_setseq_8* rng,
- uint8_t initstate, uint8_t initseq)
-{
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_8_step_r(rng);
- rng->state += initstate;
- pcg_setseq_8_step_r(rng);
-}
-
-inline void pcg_oneseq_16_srandom_r(struct pcg_state_16* rng,
- uint16_t initstate)
-{
- rng->state = 0U;
- pcg_oneseq_16_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_16_step_r(rng);
-}
-
-inline void pcg_mcg_16_srandom_r(struct pcg_state_16* rng, uint16_t initstate)
-{
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_16_srandom_r(struct pcg_state_16* rng,
- uint16_t initstate)
-{
- rng->state = 0U;
- pcg_unique_16_step_r(rng);
- rng->state += initstate;
- pcg_unique_16_step_r(rng);
-}
-
-inline void pcg_setseq_16_srandom_r(struct pcg_state_setseq_16* rng,
- uint16_t initstate, uint16_t initseq)
-{
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_16_step_r(rng);
- rng->state += initstate;
- pcg_setseq_16_step_r(rng);
-}
-
-inline void pcg_oneseq_32_srandom_r(struct pcg_state_32* rng,
- uint32_t initstate)
-{
- rng->state = 0U;
- pcg_oneseq_32_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_32_step_r(rng);
-}
-
-inline void pcg_mcg_32_srandom_r(struct pcg_state_32* rng, uint32_t initstate)
-{
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_32_srandom_r(struct pcg_state_32* rng,
- uint32_t initstate)
-{
- rng->state = 0U;
- pcg_unique_32_step_r(rng);
- rng->state += initstate;
- pcg_unique_32_step_r(rng);
-}
-
-inline void pcg_setseq_32_srandom_r(struct pcg_state_setseq_32* rng,
- uint32_t initstate, uint32_t initseq)
-{
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_32_step_r(rng);
- rng->state += initstate;
- pcg_setseq_32_step_r(rng);
-}
-
-inline void pcg_oneseq_64_srandom_r(struct pcg_state_64* rng,
- uint64_t initstate)
-{
- rng->state = 0U;
- pcg_oneseq_64_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_64_step_r(rng);
-}
-
-inline void pcg_mcg_64_srandom_r(struct pcg_state_64* rng, uint64_t initstate)
-{
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_64_srandom_r(struct pcg_state_64* rng,
- uint64_t initstate)
-{
- rng->state = 0U;
- pcg_unique_64_step_r(rng);
- rng->state += initstate;
- pcg_unique_64_step_r(rng);
-}
-
-inline void pcg_setseq_64_srandom_r(struct pcg_state_setseq_64* rng,
- uint64_t initstate, uint64_t initseq)
-{
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_64_step_r(rng);
- rng->state += initstate;
- pcg_setseq_64_step_r(rng);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_oneseq_128_srandom_r(struct pcg_state_128* rng,
- pcg128_t initstate)
-{
- rng->state = 0U;
- pcg_oneseq_128_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_128_step_r(rng);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_mcg_128_srandom_r(struct pcg_state_128* rng, pcg128_t initstate)
-{
- rng->state = initstate | 1u;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_unique_128_srandom_r(struct pcg_state_128* rng,
- pcg128_t initstate)
-{
- rng->state = 0U;
- pcg_unique_128_step_r(rng);
- rng->state += initstate;
- pcg_unique_128_step_r(rng);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_setseq_128_srandom_r(struct pcg_state_setseq_128* rng,
- pcg128_t initstate, pcg128_t initseq)
-{
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_128_step_r(rng);
- rng->state += initstate;
- pcg_setseq_128_step_r(rng);
-}
-#endif
-
-/* Now, finally we create each of the individual generators. We provide
- * a random_r function that provides a random number of the appropriate
- * type (using the full range of the type) and a boundedrand_r version
- * that provides
- *
- * Implementation notes for boundedrand_r:
- *
- * To avoid bias, we need to make the range of the RNG a multiple of
- * bound, which we do by dropping output less than a threshold.
- * Let's consider a 32-bit case... A naive scheme to calculate the
- * threshold would be to do
- *
- * uint32_t threshold = 0x100000000ull % bound;
- *
- * but 64-bit div/mod is slower than 32-bit div/mod (especially on
- * 32-bit platforms). In essence, we do
- *
- * uint32_t threshold = (0x100000000ull-bound) % bound;
- *
- * because this version will calculate the same modulus, but the LHS
- * value is less than 2^32.
- *
- * (Note that using modulo is only wise for good RNGs, poorer RNGs
- * such as raw LCGs do better using a technique based on division.)
- * Empricical tests show that division is preferable to modulus for
- * reducting the range of an RNG. It's faster, and sometimes it can
- * even be statistically prefereable.
- */
-
-/* Generation functions for XSH RS */
-
-inline uint8_t pcg_oneseq_16_xsh_rs_8_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_oneseq_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t pcg_oneseq_16_xsh_rs_8_boundedrand_r(struct pcg_state_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_oneseq_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rs_16_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_oneseq_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rs_16_boundedrand_r(struct pcg_state_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_oneseq_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rs_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rs_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_oneseq_128_xsh_rs_64_random_r(struct pcg_state_128* rng)
-{
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_oneseq_128_xsh_rs_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_unique_16_xsh_rs_8_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_unique_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t pcg_unique_16_xsh_rs_8_boundedrand_r(struct pcg_state_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_unique_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_unique_32_xsh_rs_16_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_unique_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t pcg_unique_32_xsh_rs_16_boundedrand_r(struct pcg_state_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_unique_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_unique_64_xsh_rs_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t pcg_unique_64_xsh_rs_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_unique_128_xsh_rs_64_random_r(struct pcg_state_128* rng)
-{
- pcg_unique_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_unique_128_xsh_rs_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_setseq_16_xsh_rs_8_random_r(struct pcg_state_setseq_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_setseq_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t
-pcg_setseq_16_xsh_rs_8_boundedrand_r(struct pcg_state_setseq_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_setseq_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rs_16_random_r(struct pcg_state_setseq_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_setseq_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rs_16_boundedrand_r(struct pcg_state_setseq_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_setseq_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rs_32_random_r(struct pcg_state_setseq_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rs_32_boundedrand_r(struct pcg_state_setseq_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rs_64_random_r(struct pcg_state_setseq_128* rng)
-{
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rs_64_boundedrand_r(struct pcg_state_setseq_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_mcg_16_xsh_rs_8_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_mcg_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t pcg_mcg_16_xsh_rs_8_boundedrand_r(struct pcg_state_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_mcg_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_mcg_32_xsh_rs_16_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_mcg_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t pcg_mcg_32_xsh_rs_16_boundedrand_r(struct pcg_state_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_mcg_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_mcg_64_xsh_rs_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_mcg_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t pcg_mcg_64_xsh_rs_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_mcg_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rs_64_random_r(struct pcg_state_128* rng)
-{
- pcg_mcg_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rs_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_mcg_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for XSH RR */
-
-inline uint8_t pcg_oneseq_16_xsh_rr_8_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_oneseq_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t pcg_oneseq_16_xsh_rr_8_boundedrand_r(struct pcg_state_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_oneseq_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rr_16_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_oneseq_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rr_16_boundedrand_r(struct pcg_state_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_oneseq_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rr_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rr_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_oneseq_128_xsh_rr_64_random_r(struct pcg_state_128* rng)
-{
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_oneseq_128_xsh_rr_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_unique_16_xsh_rr_8_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_unique_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t pcg_unique_16_xsh_rr_8_boundedrand_r(struct pcg_state_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_unique_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_unique_32_xsh_rr_16_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_unique_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t pcg_unique_32_xsh_rr_16_boundedrand_r(struct pcg_state_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_unique_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_unique_64_xsh_rr_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_unique_64_xsh_rr_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_unique_128_xsh_rr_64_random_r(struct pcg_state_128* rng)
-{
- pcg_unique_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_unique_128_xsh_rr_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_setseq_16_xsh_rr_8_random_r(struct pcg_state_setseq_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_setseq_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t
-pcg_setseq_16_xsh_rr_8_boundedrand_r(struct pcg_state_setseq_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_setseq_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rr_16_random_r(struct pcg_state_setseq_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_setseq_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rr_16_boundedrand_r(struct pcg_state_setseq_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_setseq_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rr_32_random_r(struct pcg_state_setseq_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rr_32_boundedrand_r(struct pcg_state_setseq_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rr_64_random_r(struct pcg_state_setseq_128* rng)
-{
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rr_64_boundedrand_r(struct pcg_state_setseq_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_mcg_16_xsh_rr_8_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_mcg_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t pcg_mcg_16_xsh_rr_8_boundedrand_r(struct pcg_state_16* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_mcg_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_mcg_32_xsh_rr_16_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_mcg_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t pcg_mcg_32_xsh_rr_16_boundedrand_r(struct pcg_state_32* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_mcg_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_mcg_64_xsh_rr_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_mcg_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_mcg_64_xsh_rr_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_mcg_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rr_64_random_r(struct pcg_state_128* rng)
-{
- pcg_mcg_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rr_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_mcg_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for RXS M XS (no MCG versions because they
- * don't make sense when you want to use the entire state)
- */
-
-inline uint8_t pcg_oneseq_8_rxs_m_xs_8_random_r(struct pcg_state_8* rng)
-{
- uint8_t oldstate = rng->state;
- pcg_oneseq_8_step_r(rng);
- return pcg_output_rxs_m_xs_8_8(oldstate);
-}
-
-inline uint8_t pcg_oneseq_8_rxs_m_xs_8_boundedrand_r(struct pcg_state_8* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_oneseq_8_rxs_m_xs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_oneseq_16_rxs_m_xs_16_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_oneseq_16_step_r(rng);
- return pcg_output_rxs_m_xs_16_16(oldstate);
-}
-
-inline uint16_t
-pcg_oneseq_16_rxs_m_xs_16_boundedrand_r(struct pcg_state_16* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_oneseq_16_rxs_m_xs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_oneseq_32_rxs_m_xs_32_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_oneseq_32_step_r(rng);
- return pcg_output_rxs_m_xs_32_32(oldstate);
-}
-
-inline uint32_t
-pcg_oneseq_32_rxs_m_xs_32_boundedrand_r(struct pcg_state_32* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_32_rxs_m_xs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint64_t pcg_oneseq_64_rxs_m_xs_64_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_rxs_m_xs_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_oneseq_64_rxs_m_xs_64_boundedrand_r(struct pcg_state_64* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_64_rxs_m_xs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_oneseq_128_rxs_m_xs_128_random_r(struct pcg_state_128* rng)
-{
- pcg_oneseq_128_step_r(rng);
- return pcg_output_rxs_m_xs_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_oneseq_128_rxs_m_xs_128_boundedrand_r(struct pcg_state_128* rng,
- pcg128_t bound)
-{
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_oneseq_128_rxs_m_xs_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint16_t pcg_unique_16_rxs_m_xs_16_random_r(struct pcg_state_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_unique_16_step_r(rng);
- return pcg_output_rxs_m_xs_16_16(oldstate);
-}
-
-inline uint16_t
-pcg_unique_16_rxs_m_xs_16_boundedrand_r(struct pcg_state_16* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_unique_16_rxs_m_xs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_unique_32_rxs_m_xs_32_random_r(struct pcg_state_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_unique_32_step_r(rng);
- return pcg_output_rxs_m_xs_32_32(oldstate);
-}
-
-inline uint32_t
-pcg_unique_32_rxs_m_xs_32_boundedrand_r(struct pcg_state_32* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_32_rxs_m_xs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint64_t pcg_unique_64_rxs_m_xs_64_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_rxs_m_xs_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_unique_64_rxs_m_xs_64_boundedrand_r(struct pcg_state_64* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_64_rxs_m_xs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_unique_128_rxs_m_xs_128_random_r(struct pcg_state_128* rng)
-{
- pcg_unique_128_step_r(rng);
- return pcg_output_rxs_m_xs_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_unique_128_rxs_m_xs_128_boundedrand_r(struct pcg_state_128* rng,
- pcg128_t bound)
-{
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_unique_128_rxs_m_xs_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_setseq_8_rxs_m_xs_8_random_r(struct pcg_state_setseq_8* rng)
-{
- uint8_t oldstate = rng->state;
- pcg_setseq_8_step_r(rng);
- return pcg_output_rxs_m_xs_8_8(oldstate);
-}
-
-inline uint8_t
-pcg_setseq_8_rxs_m_xs_8_boundedrand_r(struct pcg_state_setseq_8* rng,
- uint8_t bound)
-{
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_setseq_8_rxs_m_xs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t
-pcg_setseq_16_rxs_m_xs_16_random_r(struct pcg_state_setseq_16* rng)
-{
- uint16_t oldstate = rng->state;
- pcg_setseq_16_step_r(rng);
- return pcg_output_rxs_m_xs_16_16(oldstate);
-}
-
-inline uint16_t
-pcg_setseq_16_rxs_m_xs_16_boundedrand_r(struct pcg_state_setseq_16* rng,
- uint16_t bound)
-{
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_setseq_16_rxs_m_xs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t
-pcg_setseq_32_rxs_m_xs_32_random_r(struct pcg_state_setseq_32* rng)
-{
- uint32_t oldstate = rng->state;
- pcg_setseq_32_step_r(rng);
- return pcg_output_rxs_m_xs_32_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_32_rxs_m_xs_32_boundedrand_r(struct pcg_state_setseq_32* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_32_rxs_m_xs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint64_t
-pcg_setseq_64_rxs_m_xs_64_random_r(struct pcg_state_setseq_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_rxs_m_xs_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_setseq_64_rxs_m_xs_64_boundedrand_r(struct pcg_state_setseq_64* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_64_rxs_m_xs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_rxs_m_xs_128_random_r(struct pcg_state_setseq_128* rng)
-{
- pcg_setseq_128_step_r(rng);
- return pcg_output_rxs_m_xs_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_rxs_m_xs_128_boundedrand_r(struct pcg_state_setseq_128* rng,
- pcg128_t bound)
-{
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_setseq_128_rxs_m_xs_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for XSL RR (only defined for "large" types) */
-
-inline uint32_t pcg_oneseq_64_xsl_rr_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_oneseq_64_xsl_rr_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_oneseq_128_xsl_rr_64_random_r(struct pcg_state_128* rng)
-{
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_oneseq_128_xsl_rr_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint32_t pcg_unique_64_xsl_rr_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_unique_64_xsl_rr_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_unique_128_xsl_rr_64_random_r(struct pcg_state_128* rng)
-{
- pcg_unique_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_unique_128_xsl_rr_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint32_t
-pcg_setseq_64_xsl_rr_32_random_r(struct pcg_state_setseq_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_64_xsl_rr_32_boundedrand_r(struct pcg_state_setseq_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsl_rr_64_random_r(struct pcg_state_setseq_128* rng)
-{
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsl_rr_64_boundedrand_r(struct pcg_state_setseq_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint32_t pcg_mcg_64_xsl_rr_32_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_mcg_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_mcg_64_xsl_rr_32_boundedrand_r(struct pcg_state_64* rng,
- uint32_t bound)
-{
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_mcg_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsl_rr_64_random_r(struct pcg_state_128* rng)
-{
- pcg_mcg_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsl_rr_64_boundedrand_r(struct pcg_state_128* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_mcg_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for XSL RR RR (only defined for "large" types) */
-
-inline uint64_t pcg_oneseq_64_xsl_rr_rr_64_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsl_rr_rr_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_oneseq_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_64* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_64_xsl_rr_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_oneseq_128_xsl_rr_rr_128_random_r(struct pcg_state_128* rng)
-{
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsl_rr_rr_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_oneseq_128_xsl_rr_rr_128_boundedrand_r(struct pcg_state_128* rng,
- pcg128_t bound)
-{
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_oneseq_128_xsl_rr_rr_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint64_t pcg_unique_64_xsl_rr_rr_64_random_r(struct pcg_state_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsl_rr_rr_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_unique_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_64* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_64_xsl_rr_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_unique_128_xsl_rr_rr_128_random_r(struct pcg_state_128* rng)
-{
- pcg_unique_128_step_r(rng);
- return pcg_output_xsl_rr_rr_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_unique_128_xsl_rr_rr_128_boundedrand_r(struct pcg_state_128* rng,
- pcg128_t bound)
-{
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_unique_128_xsl_rr_rr_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint64_t
-pcg_setseq_64_xsl_rr_rr_64_random_r(struct pcg_state_setseq_64* rng)
-{
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsl_rr_rr_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_setseq_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_setseq_64* rng,
- uint64_t bound)
-{
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_64_xsl_rr_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_xsl_rr_rr_128_random_r(struct pcg_state_setseq_128* rng)
-{
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsl_rr_rr_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_xsl_rr_rr_128_boundedrand_r(struct pcg_state_setseq_128* rng,
- pcg128_t bound)
-{
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_setseq_128_xsl_rr_rr_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-//// Typedefs
-typedef struct pcg_state_setseq_64 pcg32_random_t;
-typedef struct pcg_state_64 pcg32s_random_t;
-typedef struct pcg_state_64 pcg32u_random_t;
-typedef struct pcg_state_64 pcg32f_random_t;
-//// random_r
-#define pcg32_random_r pcg_setseq_64_xsh_rr_32_random_r
-#define pcg32s_random_r pcg_oneseq_64_xsh_rr_32_random_r
-#define pcg32u_random_r pcg_unique_64_xsh_rr_32_random_r
-#define pcg32f_random_r pcg_mcg_64_xsh_rs_32_random_r
-//// boundedrand_r
-#define pcg32_boundedrand_r pcg_setseq_64_xsh_rr_32_boundedrand_r
-#define pcg32s_boundedrand_r pcg_oneseq_64_xsh_rr_32_boundedrand_r
-#define pcg32u_boundedrand_r pcg_unique_64_xsh_rr_32_boundedrand_r
-#define pcg32f_boundedrand_r pcg_mcg_64_xsh_rs_32_boundedrand_r
-//// srandom_r
-#define pcg32_srandom_r pcg_setseq_64_srandom_r
-#define pcg32s_srandom_r pcg_oneseq_64_srandom_r
-#define pcg32u_srandom_r pcg_unique_64_srandom_r
-#define pcg32f_srandom_r pcg_mcg_64_srandom_r
-//// advance_r
-#define pcg32_advance_r pcg_setseq_64_advance_r
-#define pcg32s_advance_r pcg_oneseq_64_advance_r
-#define pcg32u_advance_r pcg_unique_64_advance_r
-#define pcg32f_advance_r pcg_mcg_64_advance_r
-
-#if PCG_HAS_128BIT_OPS
-//// Typedefs
-typedef struct pcg_state_setseq_128 pcg64_random_t;
-typedef struct pcg_state_128 pcg64s_random_t;
-typedef struct pcg_state_128 pcg64u_random_t;
-typedef struct pcg_state_128 pcg64f_random_t;
-//// random_r
-#define pcg64_random_r pcg_setseq_128_xsl_rr_64_random_r
-#define pcg64s_random_r pcg_oneseq_128_xsl_rr_64_random_r
-#define pcg64u_random_r pcg_unique_128_xsl_rr_64_random_r
-#define pcg64f_random_r pcg_mcg_128_xsl_rr_64_random_r
-//// boundedrand_r
-#define pcg64_boundedrand_r pcg_setseq_128_xsl_rr_64_boundedrand_r
-#define pcg64s_boundedrand_r pcg_oneseq_128_xsl_rr_64_boundedrand_r
-#define pcg64u_boundedrand_r pcg_unique_128_xsl_rr_64_boundedrand_r
-#define pcg64f_boundedrand_r pcg_mcg_128_xsl_rr_64_boundedrand_r
-//// srandom_r
-#define pcg64_srandom_r pcg_setseq_128_srandom_r
-#define pcg64s_srandom_r pcg_oneseq_128_srandom_r
-#define pcg64u_srandom_r pcg_unique_128_srandom_r
-#define pcg64f_srandom_r pcg_mcg_128_srandom_r
-//// advance_r
-#define pcg64_advance_r pcg_setseq_128_advance_r
-#define pcg64s_advance_r pcg_oneseq_128_advance_r
-#define pcg64u_advance_r pcg_unique_128_advance_r
-#define pcg64f_advance_r pcg_mcg_128_advance_r
-#endif
-
-//// Typedefs
-typedef struct pcg_state_8 pcg8si_random_t;
-typedef struct pcg_state_16 pcg16si_random_t;
-typedef struct pcg_state_32 pcg32si_random_t;
-typedef struct pcg_state_64 pcg64si_random_t;
-//// random_r
-#define pcg8si_random_r pcg_oneseq_8_rxs_m_xs_8_random_r
-#define pcg16si_random_r pcg_oneseq_16_rxs_m_xs_16_random_r
-#define pcg32si_random_r pcg_oneseq_32_rxs_m_xs_32_random_r
-#define pcg64si_random_r pcg_oneseq_64_rxs_m_xs_64_random_r
-//// boundedrand_r
-#define pcg8si_boundedrand_r pcg_oneseq_8_rxs_m_xs_8_boundedrand_r
-#define pcg16si_boundedrand_r pcg_oneseq_16_rxs_m_xs_16_boundedrand_r
-#define pcg32si_boundedrand_r pcg_oneseq_32_rxs_m_xs_32_boundedrand_r
-#define pcg64si_boundedrand_r pcg_oneseq_64_rxs_m_xs_64_boundedrand_r
-//// srandom_r
-#define pcg8si_srandom_r pcg_oneseq_8_srandom_r
-#define pcg16si_srandom_r pcg_oneseq_16_srandom_r
-#define pcg32si_srandom_r pcg_oneseq_32_srandom_r
-#define pcg64si_srandom_r pcg_oneseq_64_srandom_r
-//// advance_r
-#define pcg8si_advance_r pcg_oneseq_8_advance_r
-#define pcg16si_advance_r pcg_oneseq_16_advance_r
-#define pcg32si_advance_r pcg_oneseq_32_advance_r
-#define pcg64si_advance_r pcg_oneseq_64_advance_r
-
-#if PCG_HAS_128BIT_OPS
-typedef struct pcg_state_128 pcg128si_random_t;
-#define pcg128si_random_r pcg_oneseq_128_rxs_m_xs_128_random_r
-#define pcg128si_boundedrand_r pcg_oneseq_128_rxs_m_xs_128_boundedrand_r
-#define pcg128si_srandom_r pcg_oneseq_128_srandom_r
-#define pcg128si_advance_r pcg_oneseq_128_advance_r
-#endif
-
-//// Typedefs
-typedef struct pcg_state_setseq_8 pcg8i_random_t;
-typedef struct pcg_state_setseq_16 pcg16i_random_t;
-typedef struct pcg_state_setseq_32 pcg32i_random_t;
-typedef struct pcg_state_setseq_64 pcg64i_random_t;
-//// random_r
-#define pcg8i_random_r pcg_setseq_8_rxs_m_xs_8_random_r
-#define pcg16i_random_r pcg_setseq_16_rxs_m_xs_16_random_r
-#define pcg32i_random_r pcg_setseq_32_rxs_m_xs_32_random_r
-#define pcg64i_random_r pcg_setseq_64_rxs_m_xs_64_random_r
-//// boundedrand_r
-#define pcg8i_boundedrand_r pcg_setseq_8_rxs_m_xs_8_boundedrand_r
-#define pcg16i_boundedrand_r pcg_setseq_16_rxs_m_xs_16_boundedrand_r
-#define pcg32i_boundedrand_r pcg_setseq_32_rxs_m_xs_32_boundedrand_r
-#define pcg64i_boundedrand_r pcg_setseq_64_rxs_m_xs_64_boundedrand_r
-//// srandom_r
-#define pcg8i_srandom_r pcg_setseq_8_srandom_r
-#define pcg16i_srandom_r pcg_setseq_16_srandom_r
-#define pcg32i_srandom_r pcg_setseq_32_srandom_r
-#define pcg64i_srandom_r pcg_setseq_64_srandom_r
-//// advance_r
-#define pcg8i_advance_r pcg_setseq_8_advance_r
-#define pcg16i_advance_r pcg_setseq_16_advance_r
-#define pcg32i_advance_r pcg_setseq_32_advance_r
-#define pcg64i_advance_r pcg_setseq_64_advance_r
-
-#if PCG_HAS_128BIT_OPS
-typedef struct pcg_state_setseq_128 pcg128i_random_t;
-#define pcg128i_random_r pcg_setseq_128_rxs_m_xs_128_random_r
-#define pcg128i_boundedrand_r pcg_setseq_128_rxs_m_xs_128_boundedrand_r
-#define pcg128i_srandom_r pcg_setseq_128_srandom_r
-#define pcg128i_advance_r pcg_setseq_128_advance_r
-#endif
-
-extern uint32_t pcg32_random();
-extern uint32_t pcg32_boundedrand(uint32_t bound);
-extern void pcg32_srandom(uint64_t seed, uint64_t seq);
-extern void pcg32_advance(uint64_t delta);
-
-#if PCG_HAS_128BIT_OPS
-extern uint64_t pcg64_random();
-extern uint64_t pcg64_boundedrand(uint64_t bound);
-extern void pcg64_srandom(pcg128_t seed, pcg128_t seq);
-extern void pcg64_advance(pcg128_t delta);
-#endif
-
-/*
- * Static initialization constants (if you can't call srandom for some
- * bizarre reason).
- */
-
-#define PCG32_INITIALIZER PCG_STATE_SETSEQ_64_INITIALIZER
-#define PCG32U_INITIALIZER PCG_STATE_UNIQUE_64_INITIALIZER
-#define PCG32S_INITIALIZER PCG_STATE_ONESEQ_64_INITIALIZER
-#define PCG32F_INITIALIZER PCG_STATE_MCG_64_INITIALIZER
-
-#if PCG_HAS_128BIT_OPS
-#define PCG64_INITIALIZER PCG_STATE_SETSEQ_128_INITIALIZER
-#define PCG64U_INITIALIZER PCG_STATE_UNIQUE_128_INITIALIZER
-#define PCG64S_INITIALIZER PCG_STATE_ONESEQ_128_INITIALIZER
-#define PCG64F_INITIALIZER PCG_STATE_MCG_128_INITIALIZER
-#endif
-
-#define PCG8SI_INITIALIZER PCG_STATE_ONESEQ_8_INITIALIZER
-#define PCG16SI_INITIALIZER PCG_STATE_ONESEQ_16_INITIALIZER
-#define PCG32SI_INITIALIZER PCG_STATE_ONESEQ_32_INITIALIZER
-#define PCG64SI_INITIALIZER PCG_STATE_ONESEQ_64_INITIALIZER
-#if PCG_HAS_128BIT_OPS
-#define PCG128SI_INITIALIZER PCG_STATE_ONESEQ_128_INITIALIZER
-#endif
-
-#define PCG8I_INITIALIZER PCG_STATE_SETSEQ_8_INITIALIZER
-#define PCG16I_INITIALIZER PCG_STATE_SETSEQ_16_INITIALIZER
-#define PCG32I_INITIALIZER PCG_STATE_SETSEQ_32_INITIALIZER
-#define PCG64I_INITIALIZER PCG_STATE_SETSEQ_64_INITIALIZER
-#if PCG_HAS_128BIT_OPS
-#define PCG128I_INITIALIZER PCG_STATE_SETSEQ_128_INITIALIZER
-#endif
-
-#if __cplusplus
-}
-#endif
-
-#endif // PCG_VARIANTS_H_INCLUDED
diff --git a/numpy/random/src/pcg64/LICENSE.md b/numpy/random/src/pcg64/LICENSE.md
deleted file mode 100644
index dd6a17ee8..000000000
--- a/numpy/random/src/pcg64/LICENSE.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# PCG64
-
-PCG Random Number Generation for C.
-
-Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-For additional information about the PCG random number generation scheme,
-including its license and other licensing options, visit
-
- http://www.pcg-random.org
diff --git a/numpy/random/src/pcg64/pcg64-benchmark.c b/numpy/random/src/pcg64/pcg64-benchmark.c
deleted file mode 100644
index 76f3ec78c..000000000
--- a/numpy/random/src/pcg64/pcg64-benchmark.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * cl pcg64-benchmark.c pcg64.c ../splitmix64/splitmix64.c /Ox
- * Measure-Command { .\xoroshiro128-benchmark.exe }
- *
- * gcc pcg64-benchmark.c pcg64.c ../splitmix64/splitmix64.c -O3 -o
- * pcg64-benchmark
- * time ./pcg64-benchmark
- */
-#include "../splitmix64/splitmix64.h"
-#include "pcg64.h"
-#include <inttypes.h>
-#include <stdio.h>
-#include <time.h>
-
-#define N 1000000000
-
-int main() {
- pcg64_random_t rng;
- uint64_t sum = 0, count = 0;
- uint64_t seed = 0xDEADBEAF;
- int i;
-#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
- rng.state = (__uint128_t)splitmix64_next(&seed) << 64;
- rng.state |= splitmix64_next(&seed);
- rng.inc = (__uint128_t)1;
-#else
- rng.state.high = splitmix64_next(&seed);
- rng.state.low = splitmix64_next(&seed);
- rng.inc.high = 0;
- rng.inc.low = 1;
-#endif
- clock_t begin = clock();
- for (i = 0; i < N; i++) {
- sum += pcg64_random_r(&rng);
- count++;
- }
- clock_t end = clock();
- double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- printf("0x%" PRIx64 "\ncount: %" PRIu64 "\n", sum, count);
- printf("%" PRIu64 " randoms per second\n",
- (uint64_t)(N / time_spent) / 1000000 * 1000000);
-}
diff --git a/numpy/random/src/pcg64/pcg64-test-data-gen.c b/numpy/random/src/pcg64/pcg64-test-data-gen.c
deleted file mode 100644
index 0c2b079a3..000000000
--- a/numpy/random/src/pcg64/pcg64-test-data-gen.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Generate testing csv files
- *
- * GCC only
- *
- * gcc pcg64-test-data-gen.c pcg64.orig.c ../splitmix64/splitmix64.c -o
- * pgc64-test-data-gen
- */
-
-#include "pcg64.orig.h"
-#include <inttypes.h>
-#include <stdio.h>
-
-#define N 1000
-
-int main() {
- pcg64_random_t rng;
- uint64_t state, seed = 0xDEADBEAF;
- state = seed;
- __uint128_t temp, s, inc;
- int i;
- uint64_t store[N];
- s = (__uint128_t)seed;
- inc = (__uint128_t)0;
- pcg64_srandom_r(&rng, s, inc);
- printf("0x%" PRIx64, (uint64_t)(rng.state >> 64));
- printf("%" PRIx64 "\n", (uint64_t)rng.state);
- printf("0x%" PRIx64, (uint64_t)(rng.inc >> 64));
- printf("%" PRIx64 "\n", (uint64_t)rng.inc);
- for (i = 0; i < N; i++) {
- store[i] = pcg64_random_r(&rng);
- }
-
- FILE *fp;
- fp = fopen("pcg64-testset-1.csv", "w");
- if (fp == NULL) {
- printf("Couldn't open file\n");
- return -1;
- }
- fprintf(fp, "seed, 0x%" PRIx64 "\n", seed);
- for (i = 0; i < N; i++) {
- fprintf(fp, "%d, 0x%" PRIx64 "\n", i, store[i]);
- if (i == 999) {
- printf("%d, 0x%" PRIx64 "\n", i, store[i]);
- }
- }
- fclose(fp);
-
- state = seed = 0;
- s = (__uint128_t)seed;
- i = (__uint128_t)0;
- pcg64_srandom_r(&rng, s, i);
- printf("0x%" PRIx64, (uint64_t)(rng.state >> 64));
- printf("%" PRIx64 "\n", (uint64_t)rng.state);
- printf("0x%" PRIx64, (uint64_t)(rng.inc >> 64));
- printf("%" PRIx64 "\n", (uint64_t)rng.inc);
- for (i = 0; i < N; i++) {
- store[i] = pcg64_random_r(&rng);
- }
- fp = fopen("pcg64-testset-2.csv", "w");
- if (fp == NULL) {
- printf("Couldn't open file\n");
- return -1;
- }
- fprintf(fp, "seed, 0x%" PRIx64 "\n", seed);
- for (i = 0; i < N; i++) {
- fprintf(fp, "%d, 0x%" PRIx64 "\n", i, store[i]);
- if (i == 999) {
- printf("%d, 0x%" PRIx64 "\n", i, store[i]);
- }
- }
- fclose(fp);
-}
diff --git a/numpy/random/src/pcg64/pcg64.c b/numpy/random/src/pcg64/pcg64.c
deleted file mode 100644
index faec0c248..000000000
--- a/numpy/random/src/pcg64/pcg64.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * PCG64 Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- * Copyright 2015 Robert Kern <robert.kern@gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
-
-#include "pcg64.h"
-
-extern inline void pcg_setseq_128_step_r(pcg_state_setseq_128 *rng);
-extern inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state);
-extern inline void pcg_setseq_128_srandom_r(pcg_state_setseq_128 *rng,
- pcg128_t initstate,
- pcg128_t initseq);
-extern inline uint64_t
-pcg_setseq_128_xsl_rr_64_random_r(pcg_state_setseq_128 *rng);
-extern inline uint64_t
-pcg_setseq_128_xsl_rr_64_boundedrand_r(pcg_state_setseq_128 *rng,
- uint64_t bound);
-extern inline void pcg_setseq_128_advance_r(pcg_state_setseq_128 *rng,
- pcg128_t delta);
-
-/* Multi-step advance functions (jump-ahead, jump-back)
- *
- * The method used here is based on Brown, "Random Number Generation
- * with Arbitrary Stride,", Transactions of the American Nuclear
- * Society (Nov. 1994). The algorithm is very similar to fast
- * exponentiation.
- *
- * Even though delta is an unsigned integer, we can pass a
- * signed integer to go backwards, it just goes "the long way round".
- */
-
-#ifndef PCG_EMULATED_128BIT_MATH
-
-pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta, pcg128_t cur_mult,
- pcg128_t cur_plus) {
- pcg128_t acc_mult = 1u;
- pcg128_t acc_plus = 0u;
- while (delta > 0) {
- if (delta & 1) {
- acc_mult *= cur_mult;
- acc_plus = acc_plus * cur_mult + cur_plus;
- }
- cur_plus = (cur_mult + 1) * cur_plus;
- cur_mult *= cur_mult;
- delta /= 2;
- }
- return acc_mult * state + acc_plus;
-}
-
-#else
-
-pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta, pcg128_t cur_mult,
- pcg128_t cur_plus) {
- pcg128_t acc_mult = PCG_128BIT_CONSTANT(0u, 1u);
- pcg128_t acc_plus = PCG_128BIT_CONSTANT(0u, 0u);
- while ((delta.high > 0) || (delta.low > 0)) {
- if (delta.low & 1) {
- acc_mult = _pcg128_mult(acc_mult, cur_mult);
- acc_plus = _pcg128_add(_pcg128_mult(acc_plus, cur_mult), cur_plus);
- }
- cur_plus = _pcg128_mult(_pcg128_add(cur_mult, PCG_128BIT_CONSTANT(0u, 1u)),
- cur_plus);
- cur_mult = _pcg128_mult(cur_mult, cur_mult);
- delta.low >>= 1;
- delta.low += delta.high & 1;
- delta.high >>= 1;
- }
- return _pcg128_add(_pcg128_mult(acc_mult, state), acc_plus);
-}
-
-#endif
-
-extern inline uint64_t pcg64_next64(pcg64_state *state);
-extern inline uint32_t pcg64_next32(pcg64_state *state);
-
-extern void pcg64_advance(pcg64_state *state, uint64_t *step) {
- pcg128_t delta;
-#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
- delta = (((pcg128_t)step[0]) << 64) | step[1];
-#else
- delta.high = step[0];
- delta.low = step[1];
-#endif
- pcg64_advance_r(state->pcg_state, delta);
-}
-
-extern void pcg64_set_seed(pcg64_state *state, uint64_t *seed, uint64_t *inc) {
- pcg128_t s, i;
-#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
- s = (((pcg128_t)seed[0]) << 64) | seed[1];
- i = (((pcg128_t)inc[0]) << 64) | inc[1];
-#else
- s.high = seed[0];
- s.low = seed[1];
- i.high = inc[0];
- i.low = inc[1];
-#endif
- pcg64_srandom_r(state->pcg_state, s, i);
-}
-
-extern void pcg64_get_state(pcg64_state *state, uint64_t *state_arr,
- int *has_uint32, uint32_t *uinteger) {
- /*
- * state_arr contains state.high, state.low, inc.high, inc.low
- * which are interpreted as the upper 64 bits (high) or lower
- * 64 bits of a uint128_t variable
- *
- */
-#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
- state_arr[0] = (uint64_t)(state->pcg_state->state >> 64);
- state_arr[1] = (uint64_t)(state->pcg_state->state & 0xFFFFFFFFFFFFFFFFULL);
- state_arr[2] = (uint64_t)(state->pcg_state->inc >> 64);
- state_arr[3] = (uint64_t)(state->pcg_state->inc & 0xFFFFFFFFFFFFFFFFULL);
-#else
- state_arr[0] = (uint64_t)state->pcg_state->state.high;
- state_arr[1] = (uint64_t)state->pcg_state->state.low;
- state_arr[2] = (uint64_t)state->pcg_state->inc.high;
- state_arr[3] = (uint64_t)state->pcg_state->inc.low;
-#endif
- has_uint32[0] = state->has_uint32;
- uinteger[0] = state->uinteger;
-}
-
-extern void pcg64_set_state(pcg64_state *state, uint64_t *state_arr,
- int has_uint32, uint32_t uinteger) {
- /*
- * state_arr contains state.high, state.low, inc.high, inc.low
- * which are interpreted as the upper 64 bits (high) or lower
- * 64 bits of a uint128_t variable
- *
- */
-#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
- state->pcg_state->state = (((pcg128_t)state_arr[0]) << 64) | state_arr[1];
- state->pcg_state->inc = (((pcg128_t)state_arr[2]) << 64) | state_arr[3];
-#else
- state->pcg_state->state.high = state_arr[0];
- state->pcg_state->state.low = state_arr[1];
- state->pcg_state->inc.high = state_arr[2];
- state->pcg_state->inc.low = state_arr[3];
-#endif
- state->has_uint32 = has_uint32;
- state->uinteger = uinteger;
-}
diff --git a/numpy/random/src/pcg64/pcg64.h b/numpy/random/src/pcg64/pcg64.h
deleted file mode 100644
index e42dc4d63..000000000
--- a/numpy/random/src/pcg64/pcg64.h
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * PCG64 Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- * Copyright 2015 Robert Kern <robert.kern@gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
-
-#ifndef PCG64_H_INCLUDED
-#define PCG64_H_INCLUDED 1
-
-#ifdef _WIN32
-#ifndef _INTTYPES
-#include "../common/stdint.h"
-#endif
-#define inline __inline __forceinline
-#else
-#include <inttypes.h>
-#if _MSC_VER >= 1900 && _M_AMD64
-#include <intrin.h>
-#pragma intrinsic(_umul128)
-#endif
-#endif
-
-#if __GNUC_GNU_INLINE__ && !defined(__cplusplus)
-#error Nonstandard GNU inlining semantics. Compile with -std=c99 or better.
-#endif
-
-#if __cplusplus
-extern "C" {
-#endif
-
-#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
-typedef __uint128_t pcg128_t;
-#define PCG_128BIT_CONSTANT(high, low) (((pcg128_t)(high) << 64) + low)
-#else
-typedef struct {
- uint64_t high;
- uint64_t low;
-} pcg128_t;
-
-static inline pcg128_t PCG_128BIT_CONSTANT(uint64_t high, uint64_t low) {
- pcg128_t result;
- result.high = high;
- result.low = low;
- return result;
-}
-
-#define PCG_EMULATED_128BIT_MATH 1
-#endif
-
-typedef struct { pcg128_t state; } pcg_state_128;
-
-typedef struct {
- pcg128_t state;
- pcg128_t inc;
-} pcg_state_setseq_128;
-
-#define PCG_DEFAULT_MULTIPLIER_128 \
- PCG_128BIT_CONSTANT(2549297995355413924ULL, 4865540595714422341ULL)
-#define PCG_DEFAULT_INCREMENT_128 \
- PCG_128BIT_CONSTANT(6364136223846793005ULL, 1442695040888963407ULL)
-#define PCG_STATE_SETSEQ_128_INITIALIZER \
- { \
- PCG_128BIT_CONSTANT(0x979c9a98d8462005ULL, 0x7d3e9cb6cfe0549bULL) \
- , PCG_128BIT_CONSTANT(0x0000000000000001ULL, 0xda3e39cb94b95bdbULL) \
- }
-
-static inline uint64_t pcg_rotr_64(uint64_t value, unsigned int rot) {
- return (value >> rot) | (value << ((-rot) & 63));
-}
-
-#ifdef PCG_EMULATED_128BIT_MATH
-
-static inline pcg128_t _pcg128_add(pcg128_t a, pcg128_t b) {
- pcg128_t result;
-
- result.low = a.low + b.low;
- result.high = a.high + b.high + (result.low < b.low);
- return result;
-}
-
-static inline void _pcg_mult64(uint64_t x, uint64_t y, uint64_t *z1,
- uint64_t *z0) {
-
-#if defined _WIN32 && _MSC_VER >= 1900 && _M_AMD64
- z0[0] = _umul128(x, y, z1);
-#else
- uint64_t x0, x1, y0, y1;
- uint64_t w0, w1, w2, t;
- /* Lower 64 bits are straightforward clock-arithmetic. */
- *z0 = x * y;
-
- x0 = x & 0xFFFFFFFFULL;
- x1 = x >> 32;
- y0 = y & 0xFFFFFFFFULL;
- y1 = y >> 32;
- w0 = x0 * y0;
- t = x1 * y0 + (w0 >> 32);
- w1 = t & 0xFFFFFFFFULL;
- w2 = t >> 32;
- w1 += x0 * y1;
- *z1 = x1 * y1 + w2 + (w1 >> 32);
-#endif
-}
-
-static inline pcg128_t _pcg128_mult(pcg128_t a, pcg128_t b) {
- uint64_t h1;
- pcg128_t result;
-
- h1 = a.high * b.low + a.low * b.high;
- _pcg_mult64(a.low, b.low, &(result.high), &(result.low));
- result.high += h1;
- return result;
-}
-
-static inline void pcg_setseq_128_step_r(pcg_state_setseq_128 *rng) {
- rng->state = _pcg128_add(_pcg128_mult(rng->state, PCG_DEFAULT_MULTIPLIER_128),
- rng->inc);
-}
-
-static inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state) {
- return pcg_rotr_64(state.high ^ state.low, state.high >> 58u);
-}
-
-static inline void pcg_setseq_128_srandom_r(pcg_state_setseq_128 *rng,
- pcg128_t initstate,
- pcg128_t initseq) {
- rng->state = PCG_128BIT_CONSTANT(0ULL, 0ULL);
- rng->inc.high = initseq.high << 1u;
- rng->inc.high |= initseq.low & 0x800000000000ULL;
- rng->inc.low = (initseq.low << 1u) | 1u;
- pcg_setseq_128_step_r(rng);
- rng->state = _pcg128_add(rng->state, initstate);
- pcg_setseq_128_step_r(rng);
-}
-
-#else /* PCG_EMULATED_128BIT_MATH */
-
-static inline void pcg_setseq_128_step_r(pcg_state_setseq_128 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128 + rng->inc;
-}
-
-static inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state) {
- return pcg_rotr_64(((uint64_t)(state >> 64u)) ^ (uint64_t)state,
- state >> 122u);
-}
-
-static inline void pcg_setseq_128_srandom_r(pcg_state_setseq_128 *rng,
- pcg128_t initstate,
- pcg128_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_128_step_r(rng);
- rng->state += initstate;
- pcg_setseq_128_step_r(rng);
-}
-
-#endif /* PCG_EMULATED_128BIT_MATH */
-
-static inline uint64_t
-pcg_setseq_128_xsl_rr_64_random_r(pcg_state_setseq_128 *rng) {
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-
-static inline uint64_t
-pcg_setseq_128_xsl_rr_64_boundedrand_r(pcg_state_setseq_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-extern pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta,
- pcg128_t cur_mult, pcg128_t cur_plus);
-
-static inline void pcg_setseq_128_advance_r(pcg_state_setseq_128 *rng,
- pcg128_t delta) {
- rng->state = pcg_advance_lcg_128(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_128, rng->inc);
-}
-
-typedef pcg_state_setseq_128 pcg64_random_t;
-#define pcg64_random_r pcg_setseq_128_xsl_rr_64_random_r
-#define pcg64_boundedrand_r pcg_setseq_128_xsl_rr_64_boundedrand_r
-#define pcg64_srandom_r pcg_setseq_128_srandom_r
-#define pcg64_advance_r pcg_setseq_128_advance_r
-#define PCG64_INITIALIZER PCG_STATE_SETSEQ_128_INITIALIZER
-
-#if __cplusplus
-}
-#endif
-
-typedef struct s_pcg64_state {
- pcg64_random_t *pcg_state;
- int has_uint32;
- uint32_t uinteger;
-} pcg64_state;
-
-static inline uint64_t pcg64_next64(pcg64_state *state) {
- return pcg64_random_r(state->pcg_state);
-}
-
-static inline uint32_t pcg64_next32(pcg64_state *state) {
- uint64_t next;
- if (state->has_uint32) {
- state->has_uint32 = 0;
- return state->uinteger;
- }
- next = pcg64_random_r(state->pcg_state);
- state->has_uint32 = 1;
- state->uinteger = (uint32_t)(next >> 32);
- return (uint32_t)(next & 0xffffffff);
-}
-
-void pcg64_advance(pcg64_state *state, uint64_t *step);
-
-void pcg64_set_seed(pcg64_state *state, uint64_t *seed, uint64_t *inc);
-
-void pcg64_get_state(pcg64_state *state, uint64_t *state_arr, int *has_uint32,
- uint32_t *uinteger);
-
-void pcg64_set_state(pcg64_state *state, uint64_t *state_arr, int has_uint32,
- uint32_t uinteger);
-
-#endif /* PCG64_H_INCLUDED */
diff --git a/numpy/random/src/pcg64/pcg64.orig.c b/numpy/random/src/pcg64/pcg64.orig.c
deleted file mode 100644
index 07e97e4b6..000000000
--- a/numpy/random/src/pcg64/pcg64.orig.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "pcg64.orig.h"
-
-extern inline void pcg_setseq_128_srandom_r(pcg64_random_t *rng,
- pcg128_t initstate,
- pcg128_t initseq);
-
-extern uint64_t pcg_rotr_64(uint64_t value, unsigned int rot);
-extern inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state);
-extern void pcg_setseq_128_step_r(struct pcg_state_setseq_128 *rng);
-extern uint64_t
-pcg_setseq_128_xsl_rr_64_random_r(struct pcg_state_setseq_128 *rng);
diff --git a/numpy/random/src/pcg64/pcg64.orig.h b/numpy/random/src/pcg64/pcg64.orig.h
deleted file mode 100644
index 74be91f31..000000000
--- a/numpy/random/src/pcg64/pcg64.orig.h
+++ /dev/null
@@ -1,2025 +0,0 @@
-/*
- * PCG Random Number Generation for C.
- *
- * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * For additional information about the PCG random number generation scheme,
- * including its license and other licensing options, visit
- *
- * http://www.pcg-random.org
- */
-
-/*
- * This code is derived from the canonical C++ PCG implementation, which
- * has many additional features and is preferable if you can use C++ in
- * your project.
- *
- * Much of the derivation was performed mechanically. In particular, the
- * output functions were generated by compiling the C++ output functions
- * into LLVM bitcode and then transforming that using the LLVM C backend
- * (from https://github.com/draperlaboratory/llvm-cbe), and then
- * postprocessing and hand editing the output.
- *
- * Much of the remaining code was generated by C-preprocessor metaprogramming.
- */
-
-#ifndef PCG_VARIANTS_H_INCLUDED
-#define PCG_VARIANTS_H_INCLUDED 1
-
-#include <inttypes.h>
-
-#if __SIZEOF_INT128__
-typedef __uint128_t pcg128_t;
-#define PCG_128BIT_CONSTANT(high, low) ((((pcg128_t)high) << 64) + low)
-#define PCG_HAS_128BIT_OPS 1
-#endif
-
-#if __GNUC_GNU_INLINE__ && !defined(__cplusplus)
-#error Nonstandard GNU inlining semantics. Compile with -std=c99 or better.
-// We could instead use macros PCG_INLINE and PCG_EXTERN_INLINE
-// but better to just reject ancient C code.
-#endif
-
-#if __cplusplus
-extern "C" {
-#endif
-
-/*
- * Rotate helper functions.
- */
-
-inline uint8_t pcg_rotr_8(uint8_t value, unsigned int rot) {
-/* Unfortunately, clang is kinda pathetic when it comes to properly
- * recognizing idiomatic rotate code, so for clang we actually provide
- * assembler directives (enabled with PCG_USE_INLINE_ASM). Boo, hiss.
- */
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm("rorb %%cl, %0" : "=r"(value) : "0"(value), "c"(rot));
- return value;
-#else
- return (value >> rot) | (value << ((-rot) & 7));
-#endif
-}
-
-inline uint16_t pcg_rotr_16(uint16_t value, unsigned int rot) {
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm("rorw %%cl, %0" : "=r"(value) : "0"(value), "c"(rot));
- return value;
-#else
- return (value >> rot) | (value << ((-rot) & 15));
-#endif
-}
-
-inline uint32_t pcg_rotr_32(uint32_t value, unsigned int rot) {
-#if PCG_USE_INLINE_ASM && __clang__ && (__x86_64__ || __i386__)
- asm("rorl %%cl, %0" : "=r"(value) : "0"(value), "c"(rot));
- return value;
-#else
- return (value >> rot) | (value << ((-rot) & 31));
-#endif
-}
-
-inline uint64_t pcg_rotr_64(uint64_t value, unsigned int rot) {
-#if 0 && PCG_USE_INLINE_ASM && __clang__ && __x86_64__
- // For whatever reason, clang actually *does* generate rotq by
- // itself, so we don't need this code.
- asm ("rorq %%cl, %0" : "=r" (value) : "0" (value), "c" (rot));
- return value;
-#else
- return (value >> rot) | (value << ((-rot) & 63));
-#endif
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_rotr_128(pcg128_t value, unsigned int rot) {
- return (value >> rot) | (value << ((-rot) & 127));
-}
-#endif
-
-/*
- * Output functions. These are the core of the PCG generation scheme.
- */
-
-// XSH RS
-
-inline uint8_t pcg_output_xsh_rs_16_8(uint16_t state) {
- return (uint8_t)(((state >> 7u) ^ state) >> ((state >> 14u) + 3u));
-}
-
-inline uint16_t pcg_output_xsh_rs_32_16(uint32_t state) {
- return (uint16_t)(((state >> 11u) ^ state) >> ((state >> 30u) + 11u));
-}
-
-inline uint32_t pcg_output_xsh_rs_64_32(uint64_t state) {
-
- return (uint32_t)(((state >> 22u) ^ state) >> ((state >> 61u) + 22u));
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_output_xsh_rs_128_64(pcg128_t state) {
- return (uint64_t)(((state >> 43u) ^ state) >> ((state >> 124u) + 45u));
-}
-#endif
-
-// XSH RR
-
-inline uint8_t pcg_output_xsh_rr_16_8(uint16_t state) {
- return pcg_rotr_8(((state >> 5u) ^ state) >> 5u, state >> 13u);
-}
-
-inline uint16_t pcg_output_xsh_rr_32_16(uint32_t state) {
- return pcg_rotr_16(((state >> 10u) ^ state) >> 12u, state >> 28u);
-}
-
-inline uint32_t pcg_output_xsh_rr_64_32(uint64_t state) {
- return pcg_rotr_32(((state >> 18u) ^ state) >> 27u, state >> 59u);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_output_xsh_rr_128_64(pcg128_t state) {
- return pcg_rotr_64(((state >> 29u) ^ state) >> 58u, state >> 122u);
-}
-#endif
-
-// RXS M XS
-
-inline uint8_t pcg_output_rxs_m_xs_8_8(uint8_t state) {
- uint8_t word = ((state >> ((state >> 6u) + 2u)) ^ state) * 217u;
- return (word >> 6u) ^ word;
-}
-
-inline uint16_t pcg_output_rxs_m_xs_16_16(uint16_t state) {
- uint16_t word = ((state >> ((state >> 13u) + 3u)) ^ state) * 62169u;
- return (word >> 11u) ^ word;
-}
-
-inline uint32_t pcg_output_rxs_m_xs_32_32(uint32_t state) {
- uint32_t word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
- return (word >> 22u) ^ word;
-}
-
-inline uint64_t pcg_output_rxs_m_xs_64_64(uint64_t state) {
- uint64_t word =
- ((state >> ((state >> 59u) + 5u)) ^ state) * 12605985483714917081ull;
- return (word >> 43u) ^ word;
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_output_rxs_m_xs_128_128(pcg128_t state) {
- pcg128_t word =
- ((state >> ((state >> 122u) + 6u)) ^ state) *
- (PCG_128BIT_CONSTANT(17766728186571221404ULL, 12605985483714917081ULL));
- // 327738287884841127335028083622016905945
- return (word >> 86u) ^ word;
-}
-#endif
-
-// XSL RR (only defined for >= 64 bits)
-
-inline uint32_t pcg_output_xsl_rr_64_32(uint64_t state) {
- return pcg_rotr_32(((uint32_t)(state >> 32u)) ^ (uint32_t)state,
- state >> 59u);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state) {
- return pcg_rotr_64(((uint64_t)(state >> 64u)) ^ (uint64_t)state,
- state >> 122u);
-}
-#endif
-
-// XSL RR RR (only defined for >= 64 bits)
-
-inline uint64_t pcg_output_xsl_rr_rr_64_64(uint64_t state) {
- uint32_t rot1 = (uint32_t)(state >> 59u);
- uint32_t high = (uint32_t)(state >> 32u);
- uint32_t low = (uint32_t)state;
- uint32_t xored = high ^ low;
- uint32_t newlow = pcg_rotr_32(xored, rot1);
- uint32_t newhigh = pcg_rotr_32(high, newlow & 31u);
- return (((uint64_t)newhigh) << 32u) | newlow;
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t pcg_output_xsl_rr_rr_128_128(pcg128_t state) {
- uint32_t rot1 = (uint32_t)(state >> 122u);
- uint64_t high = (uint64_t)(state >> 64u);
- uint64_t low = (uint64_t)state;
- uint64_t xored = high ^ low;
- uint64_t newlow = pcg_rotr_64(xored, rot1);
- uint64_t newhigh = pcg_rotr_64(high, newlow & 63u);
- return (((pcg128_t)newhigh) << 64u) | newlow;
-}
-#endif
-
-#define PCG_DEFAULT_MULTIPLIER_8 141U
-#define PCG_DEFAULT_MULTIPLIER_16 12829U
-#define PCG_DEFAULT_MULTIPLIER_32 747796405U
-#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
-
-#define PCG_DEFAULT_INCREMENT_8 77U
-#define PCG_DEFAULT_INCREMENT_16 47989U
-#define PCG_DEFAULT_INCREMENT_32 2891336453U
-#define PCG_DEFAULT_INCREMENT_64 1442695040888963407ULL
-
-#if PCG_HAS_128BIT_OPS
-#define PCG_DEFAULT_MULTIPLIER_128 \
- PCG_128BIT_CONSTANT(2549297995355413924ULL, 4865540595714422341ULL)
-#define PCG_DEFAULT_INCREMENT_128 \
- PCG_128BIT_CONSTANT(6364136223846793005ULL, 1442695040888963407ULL)
-#endif
-
- /*
- * Static initialization constants (if you can't call srandom for some
- * bizarre reason).
- */
-
-#define PCG_STATE_ONESEQ_8_INITIALIZER \
- { 0xd7U }
-#define PCG_STATE_ONESEQ_16_INITIALIZER \
- { 0x20dfU }
-#define PCG_STATE_ONESEQ_32_INITIALIZER \
- { 0x46b56677U }
-#define PCG_STATE_ONESEQ_64_INITIALIZER \
- { 0x4d595df4d0f33173ULL }
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_ONESEQ_128_INITIALIZER \
- { PCG_128BIT_CONSTANT(0xb8dc10e158a92392ULL, 0x98046df007ec0a53ULL) }
-#endif
-
-#define PCG_STATE_UNIQUE_8_INITIALIZER PCG_STATE_ONESEQ_8_INITIALIZER
-#define PCG_STATE_UNIQUE_16_INITIALIZER PCG_STATE_ONESEQ_16_INITIALIZER
-#define PCG_STATE_UNIQUE_32_INITIALIZER PCG_STATE_ONESEQ_32_INITIALIZER
-#define PCG_STATE_UNIQUE_64_INITIALIZER PCG_STATE_ONESEQ_64_INITIALIZER
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_UNIQUE_128_INITIALIZER PCG_STATE_ONESEQ_128_INITIALIZER
-#endif
-
-#define PCG_STATE_MCG_8_INITIALIZER \
- { 0xe5U }
-#define PCG_STATE_MCG_16_INITIALIZER \
- { 0xa5e5U }
-#define PCG_STATE_MCG_32_INITIALIZER \
- { 0xd15ea5e5U }
-#define PCG_STATE_MCG_64_INITIALIZER \
- { 0xcafef00dd15ea5e5ULL }
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_MCG_128_INITIALIZER \
- { PCG_128BIT_CONSTANT(0x0000000000000000ULL, 0xcafef00dd15ea5e5ULL) }
-#endif
-
-#define PCG_STATE_SETSEQ_8_INITIALIZER \
- { 0x9bU, 0xdbU }
-#define PCG_STATE_SETSEQ_16_INITIALIZER \
- { 0xe39bU, 0x5bdbU }
-#define PCG_STATE_SETSEQ_32_INITIALIZER \
- { 0xec02d89bU, 0x94b95bdbU }
-#define PCG_STATE_SETSEQ_64_INITIALIZER \
- { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL }
-#if PCG_HAS_128BIT_OPS
-#define PCG_STATE_SETSEQ_128_INITIALIZER \
- { \
- PCG_128BIT_CONSTANT(0x979c9a98d8462005ULL, 0x7d3e9cb6cfe0549bULL) \
- , PCG_128BIT_CONSTANT(0x0000000000000001ULL, 0xda3e39cb94b95bdbULL) \
- }
-#endif
-
-/* Representations for the oneseq, mcg, and unique variants */
-
-struct pcg_state_8 {
- uint8_t state;
-};
-
-struct pcg_state_16 {
- uint16_t state;
-};
-
-struct pcg_state_32 {
- uint32_t state;
-};
-
-struct pcg_state_64 {
- uint64_t state;
-};
-
-#if PCG_HAS_128BIT_OPS
-struct pcg_state_128 {
- pcg128_t state;
-};
-#endif
-
-/* Representations setseq variants */
-
-struct pcg_state_setseq_8 {
- uint8_t state;
- uint8_t inc;
-};
-
-struct pcg_state_setseq_16 {
- uint16_t state;
- uint16_t inc;
-};
-
-struct pcg_state_setseq_32 {
- uint32_t state;
- uint32_t inc;
-};
-
-struct pcg_state_setseq_64 {
- uint64_t state;
- uint64_t inc;
-};
-
-#if PCG_HAS_128BIT_OPS
-struct pcg_state_setseq_128 {
- pcg128_t state;
- pcg128_t inc;
-};
-#endif
-
-/* Multi-step advance functions (jump-ahead, jump-back) */
-
-extern uint8_t pcg_advance_lcg_8(uint8_t state, uint8_t delta, uint8_t cur_mult,
- uint8_t cur_plus);
-extern uint16_t pcg_advance_lcg_16(uint16_t state, uint16_t delta,
- uint16_t cur_mult, uint16_t cur_plus);
-extern uint32_t pcg_advance_lcg_32(uint32_t state, uint32_t delta,
- uint32_t cur_mult, uint32_t cur_plus);
-extern uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta,
- uint64_t cur_mult, uint64_t cur_plus);
-
-#if PCG_HAS_128BIT_OPS
-extern pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta,
- pcg128_t cur_mult, pcg128_t cur_plus);
-#endif
-
-/* Functions to advance the underlying LCG, one version for each size and
- * each style. These functions are considered semi-private. There is rarely
- * a good reason to call them directly.
- */
-
-inline void pcg_oneseq_8_step_r(struct pcg_state_8 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8 + PCG_DEFAULT_INCREMENT_8;
-}
-
-inline void pcg_oneseq_8_advance_r(struct pcg_state_8 *rng, uint8_t delta) {
- rng->state = pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8,
- PCG_DEFAULT_INCREMENT_8);
-}
-
-inline void pcg_mcg_8_step_r(struct pcg_state_8 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8;
-}
-
-inline void pcg_mcg_8_advance_r(struct pcg_state_8 *rng, uint8_t delta) {
- rng->state =
- pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8, 0u);
-}
-
-inline void pcg_unique_8_step_r(struct pcg_state_8 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_8 + (uint8_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_8_advance_r(struct pcg_state_8 *rng, uint8_t delta) {
- rng->state = pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8,
- (uint8_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_8_step_r(struct pcg_state_setseq_8 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_8 + rng->inc;
-}
-
-inline void pcg_setseq_8_advance_r(struct pcg_state_setseq_8 *rng,
- uint8_t delta) {
- rng->state =
- pcg_advance_lcg_8(rng->state, delta, PCG_DEFAULT_MULTIPLIER_8, rng->inc);
-}
-
-inline void pcg_oneseq_16_step_r(struct pcg_state_16 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_16 + PCG_DEFAULT_INCREMENT_16;
-}
-
-inline void pcg_oneseq_16_advance_r(struct pcg_state_16 *rng, uint16_t delta) {
- rng->state = pcg_advance_lcg_16(rng->state, delta, PCG_DEFAULT_MULTIPLIER_16,
- PCG_DEFAULT_INCREMENT_16);
-}
-
-inline void pcg_mcg_16_step_r(struct pcg_state_16 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_16;
-}
-
-inline void pcg_mcg_16_advance_r(struct pcg_state_16 *rng, uint16_t delta) {
- rng->state =
- pcg_advance_lcg_16(rng->state, delta, PCG_DEFAULT_MULTIPLIER_16, 0u);
-}
-
-inline void pcg_unique_16_step_r(struct pcg_state_16 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_16 + (uint16_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_16_advance_r(struct pcg_state_16 *rng, uint16_t delta) {
- rng->state = pcg_advance_lcg_16(rng->state, delta, PCG_DEFAULT_MULTIPLIER_16,
- (uint16_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_16_step_r(struct pcg_state_setseq_16 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_16 + rng->inc;
-}
-
-inline void pcg_setseq_16_advance_r(struct pcg_state_setseq_16 *rng,
- uint16_t delta) {
- rng->state = pcg_advance_lcg_16(rng->state, delta, PCG_DEFAULT_MULTIPLIER_16,
- rng->inc);
-}
-
-inline void pcg_oneseq_32_step_r(struct pcg_state_32 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_32 + PCG_DEFAULT_INCREMENT_32;
-}
-
-inline void pcg_oneseq_32_advance_r(struct pcg_state_32 *rng, uint32_t delta) {
- rng->state = pcg_advance_lcg_32(rng->state, delta, PCG_DEFAULT_MULTIPLIER_32,
- PCG_DEFAULT_INCREMENT_32);
-}
-
-inline void pcg_mcg_32_step_r(struct pcg_state_32 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_32;
-}
-
-inline void pcg_mcg_32_advance_r(struct pcg_state_32 *rng, uint32_t delta) {
- rng->state =
- pcg_advance_lcg_32(rng->state, delta, PCG_DEFAULT_MULTIPLIER_32, 0u);
-}
-
-inline void pcg_unique_32_step_r(struct pcg_state_32 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_32 + (uint32_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_32_advance_r(struct pcg_state_32 *rng, uint32_t delta) {
- rng->state = pcg_advance_lcg_32(rng->state, delta, PCG_DEFAULT_MULTIPLIER_32,
- (uint32_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_32_step_r(struct pcg_state_setseq_32 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_32 + rng->inc;
-}
-
-inline void pcg_setseq_32_advance_r(struct pcg_state_setseq_32 *rng,
- uint32_t delta) {
- rng->state = pcg_advance_lcg_32(rng->state, delta, PCG_DEFAULT_MULTIPLIER_32,
- rng->inc);
-}
-
-inline void pcg_oneseq_64_step_r(struct pcg_state_64 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_64 + PCG_DEFAULT_INCREMENT_64;
-}
-
-inline void pcg_oneseq_64_advance_r(struct pcg_state_64 *rng, uint64_t delta) {
- rng->state = pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64,
- PCG_DEFAULT_INCREMENT_64);
-}
-
-inline void pcg_mcg_64_step_r(struct pcg_state_64 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64;
-}
-
-inline void pcg_mcg_64_advance_r(struct pcg_state_64 *rng, uint64_t delta) {
- rng->state =
- pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64, 0u);
-}
-
-inline void pcg_unique_64_step_r(struct pcg_state_64 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_64 + (uint64_t)(((intptr_t)rng) | 1u);
-}
-
-inline void pcg_unique_64_advance_r(struct pcg_state_64 *rng, uint64_t delta) {
- rng->state = pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64,
- (uint64_t)(((intptr_t)rng) | 1u));
-}
-
-inline void pcg_setseq_64_step_r(struct pcg_state_setseq_64 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_64 + rng->inc;
-}
-
-inline void pcg_setseq_64_advance_r(struct pcg_state_setseq_64 *rng,
- uint64_t delta) {
- rng->state = pcg_advance_lcg_64(rng->state, delta, PCG_DEFAULT_MULTIPLIER_64,
- rng->inc);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_oneseq_128_step_r(struct pcg_state_128 *rng) {
- rng->state =
- rng->state * PCG_DEFAULT_MULTIPLIER_128 + PCG_DEFAULT_INCREMENT_128;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_oneseq_128_advance_r(struct pcg_state_128 *rng,
- pcg128_t delta) {
- rng->state = pcg_advance_lcg_128(
- rng->state, delta, PCG_DEFAULT_MULTIPLIER_128, PCG_DEFAULT_INCREMENT_128);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_mcg_128_step_r(struct pcg_state_128 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_mcg_128_advance_r(struct pcg_state_128 *rng, pcg128_t delta) {
- rng->state =
- pcg_advance_lcg_128(rng->state, delta, PCG_DEFAULT_MULTIPLIER_128, 0u);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_unique_128_step_r(struct pcg_state_128 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128 +
- (pcg128_t)(((intptr_t)rng) | 1u);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_unique_128_advance_r(struct pcg_state_128 *rng,
- pcg128_t delta) {
- rng->state =
- pcg_advance_lcg_128(rng->state, delta, PCG_DEFAULT_MULTIPLIER_128,
- (pcg128_t)(((intptr_t)rng) | 1u));
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_setseq_128_step_r(struct pcg_state_setseq_128 *rng) {
- rng->state = rng->state * PCG_DEFAULT_MULTIPLIER_128 + rng->inc;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_setseq_128_advance_r(struct pcg_state_setseq_128 *rng,
- pcg128_t delta) {
- rng->state = pcg_advance_lcg_128(rng->state, delta,
- PCG_DEFAULT_MULTIPLIER_128, rng->inc);
-}
-#endif
-
-/* Functions to seed the RNG state, one version for each size and each
- * style. Unlike the step functions, regular users can and should call
- * these functions.
- */
-
-inline void pcg_oneseq_8_srandom_r(struct pcg_state_8 *rng, uint8_t initstate) {
- rng->state = 0U;
- pcg_oneseq_8_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_8_step_r(rng);
-}
-
-inline void pcg_mcg_8_srandom_r(struct pcg_state_8 *rng, uint8_t initstate) {
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_8_srandom_r(struct pcg_state_8 *rng, uint8_t initstate) {
- rng->state = 0U;
- pcg_unique_8_step_r(rng);
- rng->state += initstate;
- pcg_unique_8_step_r(rng);
-}
-
-inline void pcg_setseq_8_srandom_r(struct pcg_state_setseq_8 *rng,
- uint8_t initstate, uint8_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_8_step_r(rng);
- rng->state += initstate;
- pcg_setseq_8_step_r(rng);
-}
-
-inline void pcg_oneseq_16_srandom_r(struct pcg_state_16 *rng,
- uint16_t initstate) {
- rng->state = 0U;
- pcg_oneseq_16_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_16_step_r(rng);
-}
-
-inline void pcg_mcg_16_srandom_r(struct pcg_state_16 *rng, uint16_t initstate) {
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_16_srandom_r(struct pcg_state_16 *rng,
- uint16_t initstate) {
- rng->state = 0U;
- pcg_unique_16_step_r(rng);
- rng->state += initstate;
- pcg_unique_16_step_r(rng);
-}
-
-inline void pcg_setseq_16_srandom_r(struct pcg_state_setseq_16 *rng,
- uint16_t initstate, uint16_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_16_step_r(rng);
- rng->state += initstate;
- pcg_setseq_16_step_r(rng);
-}
-
-inline void pcg_oneseq_32_srandom_r(struct pcg_state_32 *rng,
- uint32_t initstate) {
- rng->state = 0U;
- pcg_oneseq_32_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_32_step_r(rng);
-}
-
-inline void pcg_mcg_32_srandom_r(struct pcg_state_32 *rng, uint32_t initstate) {
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_32_srandom_r(struct pcg_state_32 *rng,
- uint32_t initstate) {
- rng->state = 0U;
- pcg_unique_32_step_r(rng);
- rng->state += initstate;
- pcg_unique_32_step_r(rng);
-}
-
-inline void pcg_setseq_32_srandom_r(struct pcg_state_setseq_32 *rng,
- uint32_t initstate, uint32_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_32_step_r(rng);
- rng->state += initstate;
- pcg_setseq_32_step_r(rng);
-}
-
-inline void pcg_oneseq_64_srandom_r(struct pcg_state_64 *rng,
- uint64_t initstate) {
- rng->state = 0U;
- pcg_oneseq_64_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_64_step_r(rng);
-}
-
-inline void pcg_mcg_64_srandom_r(struct pcg_state_64 *rng, uint64_t initstate) {
- rng->state = initstate | 1u;
-}
-
-inline void pcg_unique_64_srandom_r(struct pcg_state_64 *rng,
- uint64_t initstate) {
- rng->state = 0U;
- pcg_unique_64_step_r(rng);
- rng->state += initstate;
- pcg_unique_64_step_r(rng);
-}
-
-inline void pcg_setseq_64_srandom_r(struct pcg_state_setseq_64 *rng,
- uint64_t initstate, uint64_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_64_step_r(rng);
- rng->state += initstate;
- pcg_setseq_64_step_r(rng);
-}
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_oneseq_128_srandom_r(struct pcg_state_128 *rng,
- pcg128_t initstate) {
- rng->state = 0U;
- pcg_oneseq_128_step_r(rng);
- rng->state += initstate;
- pcg_oneseq_128_step_r(rng);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_mcg_128_srandom_r(struct pcg_state_128 *rng,
- pcg128_t initstate) {
- rng->state = initstate | 1u;
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_unique_128_srandom_r(struct pcg_state_128 *rng,
- pcg128_t initstate) {
- rng->state = 0U;
- pcg_unique_128_step_r(rng);
- rng->state += initstate;
- pcg_unique_128_step_r(rng);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline void pcg_setseq_128_srandom_r(struct pcg_state_setseq_128 *rng,
- pcg128_t initstate, pcg128_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg_setseq_128_step_r(rng);
- rng->state += initstate;
- pcg_setseq_128_step_r(rng);
-}
-#endif
-
-/* Now, finally we create each of the individual generators. We provide
- * a random_r function that provides a random number of the appropriate
- * type (using the full range of the type) and a boundedrand_r version
- * that provides
- *
- * Implementation notes for boundedrand_r:
- *
- * To avoid bias, we need to make the range of the RNG a multiple of
- * bound, which we do by dropping output less than a threshold.
- * Let's consider a 32-bit case... A naive scheme to calculate the
- * threshold would be to do
- *
- * uint32_t threshold = 0x100000000ull % bound;
- *
- * but 64-bit div/mod is slower than 32-bit div/mod (especially on
- * 32-bit platforms). In essence, we do
- *
- * uint32_t threshold = (0x100000000ull-bound) % bound;
- *
- * because this version will calculate the same modulus, but the LHS
- * value is less than 2^32.
- *
- * (Note that using modulo is only wise for good RNGs, poorer RNGs
- * such as raw LCGs do better using a technique based on division.)
- * Empricical tests show that division is preferable to modulus for
- * reducting the range of an RNG. It's faster, and sometimes it can
- * even be statistically prefereable.
- */
-
-/* Generation functions for XSH RS */
-
-inline uint8_t pcg_oneseq_16_xsh_rs_8_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_oneseq_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t pcg_oneseq_16_xsh_rs_8_boundedrand_r(struct pcg_state_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_oneseq_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rs_16_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_oneseq_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rs_16_boundedrand_r(struct pcg_state_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_oneseq_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rs_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rs_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_oneseq_128_xsh_rs_64_random_r(struct pcg_state_128 *rng) {
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_oneseq_128_xsh_rs_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_unique_16_xsh_rs_8_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_unique_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t pcg_unique_16_xsh_rs_8_boundedrand_r(struct pcg_state_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_unique_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_unique_32_xsh_rs_16_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_unique_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t pcg_unique_32_xsh_rs_16_boundedrand_r(struct pcg_state_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_unique_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_unique_64_xsh_rs_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t pcg_unique_64_xsh_rs_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_unique_128_xsh_rs_64_random_r(struct pcg_state_128 *rng) {
- pcg_unique_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_unique_128_xsh_rs_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t
-pcg_setseq_16_xsh_rs_8_random_r(struct pcg_state_setseq_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_setseq_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t
-pcg_setseq_16_xsh_rs_8_boundedrand_r(struct pcg_state_setseq_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_setseq_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rs_16_random_r(struct pcg_state_setseq_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_setseq_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rs_16_boundedrand_r(struct pcg_state_setseq_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_setseq_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rs_32_random_r(struct pcg_state_setseq_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rs_32_boundedrand_r(struct pcg_state_setseq_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rs_64_random_r(struct pcg_state_setseq_128 *rng) {
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rs_64_boundedrand_r(struct pcg_state_setseq_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_mcg_16_xsh_rs_8_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_mcg_16_step_r(rng);
- return pcg_output_xsh_rs_16_8(oldstate);
-}
-
-inline uint8_t pcg_mcg_16_xsh_rs_8_boundedrand_r(struct pcg_state_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_mcg_16_xsh_rs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_mcg_32_xsh_rs_16_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_mcg_32_step_r(rng);
- return pcg_output_xsh_rs_32_16(oldstate);
-}
-
-inline uint16_t pcg_mcg_32_xsh_rs_16_boundedrand_r(struct pcg_state_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_mcg_32_xsh_rs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_mcg_64_xsh_rs_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_mcg_64_step_r(rng);
- return pcg_output_xsh_rs_64_32(oldstate);
-}
-
-inline uint32_t pcg_mcg_64_xsh_rs_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_mcg_64_xsh_rs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rs_64_random_r(struct pcg_state_128 *rng) {
- pcg_mcg_128_step_r(rng);
- return pcg_output_xsh_rs_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rs_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_mcg_128_xsh_rs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for XSH RR */
-
-inline uint8_t pcg_oneseq_16_xsh_rr_8_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_oneseq_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t pcg_oneseq_16_xsh_rr_8_boundedrand_r(struct pcg_state_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_oneseq_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rr_16_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_oneseq_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t pcg_oneseq_32_xsh_rr_16_boundedrand_r(struct pcg_state_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_oneseq_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rr_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_oneseq_64_xsh_rr_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_oneseq_128_xsh_rr_64_random_r(struct pcg_state_128 *rng) {
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_oneseq_128_xsh_rr_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_unique_16_xsh_rr_8_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_unique_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t pcg_unique_16_xsh_rr_8_boundedrand_r(struct pcg_state_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_unique_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_unique_32_xsh_rr_16_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_unique_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t pcg_unique_32_xsh_rr_16_boundedrand_r(struct pcg_state_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_unique_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_unique_64_xsh_rr_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_unique_64_xsh_rr_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_unique_128_xsh_rr_64_random_r(struct pcg_state_128 *rng) {
- pcg_unique_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_unique_128_xsh_rr_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t
-pcg_setseq_16_xsh_rr_8_random_r(struct pcg_state_setseq_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_setseq_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t
-pcg_setseq_16_xsh_rr_8_boundedrand_r(struct pcg_state_setseq_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_setseq_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rr_16_random_r(struct pcg_state_setseq_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_setseq_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t
-pcg_setseq_32_xsh_rr_16_boundedrand_r(struct pcg_state_setseq_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_setseq_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rr_32_random_r(struct pcg_state_setseq_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_64_xsh_rr_32_boundedrand_r(struct pcg_state_setseq_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rr_64_random_r(struct pcg_state_setseq_128 *rng) {
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsh_rr_64_boundedrand_r(struct pcg_state_setseq_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t pcg_mcg_16_xsh_rr_8_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_mcg_16_step_r(rng);
- return pcg_output_xsh_rr_16_8(oldstate);
-}
-
-inline uint8_t pcg_mcg_16_xsh_rr_8_boundedrand_r(struct pcg_state_16 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_mcg_16_xsh_rr_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_mcg_32_xsh_rr_16_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_mcg_32_step_r(rng);
- return pcg_output_xsh_rr_32_16(oldstate);
-}
-
-inline uint16_t pcg_mcg_32_xsh_rr_16_boundedrand_r(struct pcg_state_32 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_mcg_32_xsh_rr_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_mcg_64_xsh_rr_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_mcg_64_step_r(rng);
- return pcg_output_xsh_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_mcg_64_xsh_rr_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_mcg_64_xsh_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rr_64_random_r(struct pcg_state_128 *rng) {
- pcg_mcg_128_step_r(rng);
- return pcg_output_xsh_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsh_rr_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_mcg_128_xsh_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for RXS M XS (no MCG versions because they
- * don't make sense when you want to use the entire state)
- */
-
-inline uint8_t pcg_oneseq_8_rxs_m_xs_8_random_r(struct pcg_state_8 *rng) {
- uint8_t oldstate = rng->state;
- pcg_oneseq_8_step_r(rng);
- return pcg_output_rxs_m_xs_8_8(oldstate);
-}
-
-inline uint8_t pcg_oneseq_8_rxs_m_xs_8_boundedrand_r(struct pcg_state_8 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_oneseq_8_rxs_m_xs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t pcg_oneseq_16_rxs_m_xs_16_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_oneseq_16_step_r(rng);
- return pcg_output_rxs_m_xs_16_16(oldstate);
-}
-
-inline uint16_t
-pcg_oneseq_16_rxs_m_xs_16_boundedrand_r(struct pcg_state_16 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_oneseq_16_rxs_m_xs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_oneseq_32_rxs_m_xs_32_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_oneseq_32_step_r(rng);
- return pcg_output_rxs_m_xs_32_32(oldstate);
-}
-
-inline uint32_t
-pcg_oneseq_32_rxs_m_xs_32_boundedrand_r(struct pcg_state_32 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_32_rxs_m_xs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint64_t pcg_oneseq_64_rxs_m_xs_64_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_rxs_m_xs_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_oneseq_64_rxs_m_xs_64_boundedrand_r(struct pcg_state_64 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_64_rxs_m_xs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_oneseq_128_rxs_m_xs_128_random_r(struct pcg_state_128 *rng) {
- pcg_oneseq_128_step_r(rng);
- return pcg_output_rxs_m_xs_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_oneseq_128_rxs_m_xs_128_boundedrand_r(struct pcg_state_128 *rng,
- pcg128_t bound) {
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_oneseq_128_rxs_m_xs_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint16_t pcg_unique_16_rxs_m_xs_16_random_r(struct pcg_state_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_unique_16_step_r(rng);
- return pcg_output_rxs_m_xs_16_16(oldstate);
-}
-
-inline uint16_t
-pcg_unique_16_rxs_m_xs_16_boundedrand_r(struct pcg_state_16 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_unique_16_rxs_m_xs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t pcg_unique_32_rxs_m_xs_32_random_r(struct pcg_state_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_unique_32_step_r(rng);
- return pcg_output_rxs_m_xs_32_32(oldstate);
-}
-
-inline uint32_t
-pcg_unique_32_rxs_m_xs_32_boundedrand_r(struct pcg_state_32 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_32_rxs_m_xs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint64_t pcg_unique_64_rxs_m_xs_64_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_rxs_m_xs_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_unique_64_rxs_m_xs_64_boundedrand_r(struct pcg_state_64 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_64_rxs_m_xs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_unique_128_rxs_m_xs_128_random_r(struct pcg_state_128 *rng) {
- pcg_unique_128_step_r(rng);
- return pcg_output_rxs_m_xs_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_unique_128_rxs_m_xs_128_boundedrand_r(struct pcg_state_128 *rng,
- pcg128_t bound) {
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_unique_128_rxs_m_xs_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint8_t
-pcg_setseq_8_rxs_m_xs_8_random_r(struct pcg_state_setseq_8 *rng) {
- uint8_t oldstate = rng->state;
- pcg_setseq_8_step_r(rng);
- return pcg_output_rxs_m_xs_8_8(oldstate);
-}
-
-inline uint8_t
-pcg_setseq_8_rxs_m_xs_8_boundedrand_r(struct pcg_state_setseq_8 *rng,
- uint8_t bound) {
- uint8_t threshold = ((uint8_t)(-bound)) % bound;
- for (;;) {
- uint8_t r = pcg_setseq_8_rxs_m_xs_8_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint16_t
-pcg_setseq_16_rxs_m_xs_16_random_r(struct pcg_state_setseq_16 *rng) {
- uint16_t oldstate = rng->state;
- pcg_setseq_16_step_r(rng);
- return pcg_output_rxs_m_xs_16_16(oldstate);
-}
-
-inline uint16_t
-pcg_setseq_16_rxs_m_xs_16_boundedrand_r(struct pcg_state_setseq_16 *rng,
- uint16_t bound) {
- uint16_t threshold = ((uint16_t)(-bound)) % bound;
- for (;;) {
- uint16_t r = pcg_setseq_16_rxs_m_xs_16_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint32_t
-pcg_setseq_32_rxs_m_xs_32_random_r(struct pcg_state_setseq_32 *rng) {
- uint32_t oldstate = rng->state;
- pcg_setseq_32_step_r(rng);
- return pcg_output_rxs_m_xs_32_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_32_rxs_m_xs_32_boundedrand_r(struct pcg_state_setseq_32 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_32_rxs_m_xs_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-inline uint64_t
-pcg_setseq_64_rxs_m_xs_64_random_r(struct pcg_state_setseq_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_rxs_m_xs_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_setseq_64_rxs_m_xs_64_boundedrand_r(struct pcg_state_setseq_64 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_64_rxs_m_xs_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_rxs_m_xs_128_random_r(struct pcg_state_setseq_128 *rng) {
- pcg_setseq_128_step_r(rng);
- return pcg_output_rxs_m_xs_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_rxs_m_xs_128_boundedrand_r(struct pcg_state_setseq_128 *rng,
- pcg128_t bound) {
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_setseq_128_rxs_m_xs_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for XSL RR (only defined for "large" types) */
-
-inline uint32_t pcg_oneseq_64_xsl_rr_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_oneseq_64_xsl_rr_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_oneseq_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_oneseq_128_xsl_rr_64_random_r(struct pcg_state_128 *rng) {
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_oneseq_128_xsl_rr_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint32_t pcg_unique_64_xsl_rr_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_unique_64_xsl_rr_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_unique_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_unique_128_xsl_rr_64_random_r(struct pcg_state_128 *rng) {
- pcg_unique_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_unique_128_xsl_rr_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint32_t
-pcg_setseq_64_xsl_rr_32_random_r(struct pcg_state_setseq_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t
-pcg_setseq_64_xsl_rr_32_boundedrand_r(struct pcg_state_setseq_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_setseq_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsl_rr_64_random_r(struct pcg_state_setseq_128 *rng) {
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t
-pcg_setseq_128_xsl_rr_64_boundedrand_r(struct pcg_state_setseq_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint32_t pcg_mcg_64_xsl_rr_32_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_mcg_64_step_r(rng);
- return pcg_output_xsl_rr_64_32(oldstate);
-}
-
-inline uint32_t pcg_mcg_64_xsl_rr_32_boundedrand_r(struct pcg_state_64 *rng,
- uint32_t bound) {
- uint32_t threshold = -bound % bound;
- for (;;) {
- uint32_t r = pcg_mcg_64_xsl_rr_32_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsl_rr_64_random_r(struct pcg_state_128 *rng) {
- pcg_mcg_128_step_r(rng);
- return pcg_output_xsl_rr_128_64(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline uint64_t pcg_mcg_128_xsl_rr_64_boundedrand_r(struct pcg_state_128 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_mcg_128_xsl_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-/* Generation functions for XSL RR RR (only defined for "large" types) */
-
-inline uint64_t pcg_oneseq_64_xsl_rr_rr_64_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_oneseq_64_step_r(rng);
- return pcg_output_xsl_rr_rr_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_oneseq_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_64 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_oneseq_64_xsl_rr_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_oneseq_128_xsl_rr_rr_128_random_r(struct pcg_state_128 *rng) {
- pcg_oneseq_128_step_r(rng);
- return pcg_output_xsl_rr_rr_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_oneseq_128_xsl_rr_rr_128_boundedrand_r(struct pcg_state_128 *rng,
- pcg128_t bound) {
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_oneseq_128_xsl_rr_rr_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint64_t pcg_unique_64_xsl_rr_rr_64_random_r(struct pcg_state_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_unique_64_step_r(rng);
- return pcg_output_xsl_rr_rr_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_unique_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_64 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_unique_64_xsl_rr_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_unique_128_xsl_rr_rr_128_random_r(struct pcg_state_128 *rng) {
- pcg_unique_128_step_r(rng);
- return pcg_output_xsl_rr_rr_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_unique_128_xsl_rr_rr_128_boundedrand_r(struct pcg_state_128 *rng,
- pcg128_t bound) {
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_unique_128_xsl_rr_rr_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-inline uint64_t
-pcg_setseq_64_xsl_rr_rr_64_random_r(struct pcg_state_setseq_64 *rng) {
- uint64_t oldstate = rng->state;
- pcg_setseq_64_step_r(rng);
- return pcg_output_xsl_rr_rr_64_64(oldstate);
-}
-
-inline uint64_t
-pcg_setseq_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_setseq_64 *rng,
- uint64_t bound) {
- uint64_t threshold = -bound % bound;
- for (;;) {
- uint64_t r = pcg_setseq_64_xsl_rr_rr_64_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_xsl_rr_rr_128_random_r(struct pcg_state_setseq_128 *rng) {
- pcg_setseq_128_step_r(rng);
- return pcg_output_xsl_rr_rr_128_128(rng->state);
-}
-#endif
-
-#if PCG_HAS_128BIT_OPS
-inline pcg128_t
-pcg_setseq_128_xsl_rr_rr_128_boundedrand_r(struct pcg_state_setseq_128 *rng,
- pcg128_t bound) {
- pcg128_t threshold = -bound % bound;
- for (;;) {
- pcg128_t r = pcg_setseq_128_xsl_rr_rr_128_random_r(rng);
- if (r >= threshold)
- return r % bound;
- }
-}
-#endif
-
-//// Typedefs
-typedef struct pcg_state_setseq_64 pcg32_random_t;
-typedef struct pcg_state_64 pcg32s_random_t;
-typedef struct pcg_state_64 pcg32u_random_t;
-typedef struct pcg_state_64 pcg32f_random_t;
-//// random_r
-#define pcg32_random_r pcg_setseq_64_xsh_rr_32_random_r
-#define pcg32s_random_r pcg_oneseq_64_xsh_rr_32_random_r
-#define pcg32u_random_r pcg_unique_64_xsh_rr_32_random_r
-#define pcg32f_random_r pcg_mcg_64_xsh_rs_32_random_r
-//// boundedrand_r
-#define pcg32_boundedrand_r pcg_setseq_64_xsh_rr_32_boundedrand_r
-#define pcg32s_boundedrand_r pcg_oneseq_64_xsh_rr_32_boundedrand_r
-#define pcg32u_boundedrand_r pcg_unique_64_xsh_rr_32_boundedrand_r
-#define pcg32f_boundedrand_r pcg_mcg_64_xsh_rs_32_boundedrand_r
-//// srandom_r
-#define pcg32_srandom_r pcg_setseq_64_srandom_r
-#define pcg32s_srandom_r pcg_oneseq_64_srandom_r
-#define pcg32u_srandom_r pcg_unique_64_srandom_r
-#define pcg32f_srandom_r pcg_mcg_64_srandom_r
-//// advance_r
-#define pcg32_advance_r pcg_setseq_64_advance_r
-#define pcg32s_advance_r pcg_oneseq_64_advance_r
-#define pcg32u_advance_r pcg_unique_64_advance_r
-#define pcg32f_advance_r pcg_mcg_64_advance_r
-
-#if PCG_HAS_128BIT_OPS
-//// Typedefs
-typedef struct pcg_state_setseq_128 pcg64_random_t;
-typedef struct pcg_state_128 pcg64s_random_t;
-typedef struct pcg_state_128 pcg64u_random_t;
-typedef struct pcg_state_128 pcg64f_random_t;
-//// random_r
-#define pcg64_random_r pcg_setseq_128_xsl_rr_64_random_r
-#define pcg64s_random_r pcg_oneseq_128_xsl_rr_64_random_r
-#define pcg64u_random_r pcg_unique_128_xsl_rr_64_random_r
-#define pcg64f_random_r pcg_mcg_128_xsl_rr_64_random_r
-//// boundedrand_r
-#define pcg64_boundedrand_r pcg_setseq_128_xsl_rr_64_boundedrand_r
-#define pcg64s_boundedrand_r pcg_oneseq_128_xsl_rr_64_boundedrand_r
-#define pcg64u_boundedrand_r pcg_unique_128_xsl_rr_64_boundedrand_r
-#define pcg64f_boundedrand_r pcg_mcg_128_xsl_rr_64_boundedrand_r
-//// srandom_r
-#define pcg64_srandom_r pcg_setseq_128_srandom_r
-#define pcg64s_srandom_r pcg_oneseq_128_srandom_r
-#define pcg64u_srandom_r pcg_unique_128_srandom_r
-#define pcg64f_srandom_r pcg_mcg_128_srandom_r
-//// advance_r
-#define pcg64_advance_r pcg_setseq_128_advance_r
-#define pcg64s_advance_r pcg_oneseq_128_advance_r
-#define pcg64u_advance_r pcg_unique_128_advance_r
-#define pcg64f_advance_r pcg_mcg_128_advance_r
-#endif
-
-//// Typedefs
-typedef struct pcg_state_8 pcg8si_random_t;
-typedef struct pcg_state_16 pcg16si_random_t;
-typedef struct pcg_state_32 pcg32si_random_t;
-typedef struct pcg_state_64 pcg64si_random_t;
-//// random_r
-#define pcg8si_random_r pcg_oneseq_8_rxs_m_xs_8_random_r
-#define pcg16si_random_r pcg_oneseq_16_rxs_m_xs_16_random_r
-#define pcg32si_random_r pcg_oneseq_32_rxs_m_xs_32_random_r
-#define pcg64si_random_r pcg_oneseq_64_rxs_m_xs_64_random_r
-//// boundedrand_r
-#define pcg8si_boundedrand_r pcg_oneseq_8_rxs_m_xs_8_boundedrand_r
-#define pcg16si_boundedrand_r pcg_oneseq_16_rxs_m_xs_16_boundedrand_r
-#define pcg32si_boundedrand_r pcg_oneseq_32_rxs_m_xs_32_boundedrand_r
-#define pcg64si_boundedrand_r pcg_oneseq_64_rxs_m_xs_64_boundedrand_r
-//// srandom_r
-#define pcg8si_srandom_r pcg_oneseq_8_srandom_r
-#define pcg16si_srandom_r pcg_oneseq_16_srandom_r
-#define pcg32si_srandom_r pcg_oneseq_32_srandom_r
-#define pcg64si_srandom_r pcg_oneseq_64_srandom_r
-//// advance_r
-#define pcg8si_advance_r pcg_oneseq_8_advance_r
-#define pcg16si_advance_r pcg_oneseq_16_advance_r
-#define pcg32si_advance_r pcg_oneseq_32_advance_r
-#define pcg64si_advance_r pcg_oneseq_64_advance_r
-
-#if PCG_HAS_128BIT_OPS
-typedef struct pcg_state_128 pcg128si_random_t;
-#define pcg128si_random_r pcg_oneseq_128_rxs_m_xs_128_random_r
-#define pcg128si_boundedrand_r pcg_oneseq_128_rxs_m_xs_128_boundedrand_r
-#define pcg128si_srandom_r pcg_oneseq_128_srandom_r
-#define pcg128si_advance_r pcg_oneseq_128_advance_r
-#endif
-
-//// Typedefs
-typedef struct pcg_state_setseq_8 pcg8i_random_t;
-typedef struct pcg_state_setseq_16 pcg16i_random_t;
-typedef struct pcg_state_setseq_32 pcg32i_random_t;
-typedef struct pcg_state_setseq_64 pcg64i_random_t;
-//// random_r
-#define pcg8i_random_r pcg_setseq_8_rxs_m_xs_8_random_r
-#define pcg16i_random_r pcg_setseq_16_rxs_m_xs_16_random_r
-#define pcg32i_random_r pcg_setseq_32_rxs_m_xs_32_random_r
-#define pcg64i_random_r pcg_setseq_64_rxs_m_xs_64_random_r
-//// boundedrand_r
-#define pcg8i_boundedrand_r pcg_setseq_8_rxs_m_xs_8_boundedrand_r
-#define pcg16i_boundedrand_r pcg_setseq_16_rxs_m_xs_16_boundedrand_r
-#define pcg32i_boundedrand_r pcg_setseq_32_rxs_m_xs_32_boundedrand_r
-#define pcg64i_boundedrand_r pcg_setseq_64_rxs_m_xs_64_boundedrand_r
-//// srandom_r
-#define pcg8i_srandom_r pcg_setseq_8_srandom_r
-#define pcg16i_srandom_r pcg_setseq_16_srandom_r
-#define pcg32i_srandom_r pcg_setseq_32_srandom_r
-#define pcg64i_srandom_r pcg_setseq_64_srandom_r
-//// advance_r
-#define pcg8i_advance_r pcg_setseq_8_advance_r
-#define pcg16i_advance_r pcg_setseq_16_advance_r
-#define pcg32i_advance_r pcg_setseq_32_advance_r
-#define pcg64i_advance_r pcg_setseq_64_advance_r
-
-#if PCG_HAS_128BIT_OPS
-typedef struct pcg_state_setseq_128 pcg128i_random_t;
-#define pcg128i_random_r pcg_setseq_128_rxs_m_xs_128_random_r
-#define pcg128i_boundedrand_r pcg_setseq_128_rxs_m_xs_128_boundedrand_r
-#define pcg128i_srandom_r pcg_setseq_128_srandom_r
-#define pcg128i_advance_r pcg_setseq_128_advance_r
-#endif
-
-extern uint32_t pcg32_random();
-extern uint32_t pcg32_boundedrand(uint32_t bound);
-extern void pcg32_srandom(uint64_t seed, uint64_t seq);
-extern void pcg32_advance(uint64_t delta);
-
-#if PCG_HAS_128BIT_OPS
-extern uint64_t pcg64_random();
-extern uint64_t pcg64_boundedrand(uint64_t bound);
-extern void pcg64_srandom(pcg128_t seed, pcg128_t seq);
-extern void pcg64_advance(pcg128_t delta);
-#endif
-
-/*
- * Static initialization constants (if you can't call srandom for some
- * bizarre reason).
- */
-
-#define PCG32_INITIALIZER PCG_STATE_SETSEQ_64_INITIALIZER
-#define PCG32U_INITIALIZER PCG_STATE_UNIQUE_64_INITIALIZER
-#define PCG32S_INITIALIZER PCG_STATE_ONESEQ_64_INITIALIZER
-#define PCG32F_INITIALIZER PCG_STATE_MCG_64_INITIALIZER
-
-#if PCG_HAS_128BIT_OPS
-#define PCG64_INITIALIZER PCG_STATE_SETSEQ_128_INITIALIZER
-#define PCG64U_INITIALIZER PCG_STATE_UNIQUE_128_INITIALIZER
-#define PCG64S_INITIALIZER PCG_STATE_ONESEQ_128_INITIALIZER
-#define PCG64F_INITIALIZER PCG_STATE_MCG_128_INITIALIZER
-#endif
-
-#define PCG8SI_INITIALIZER PCG_STATE_ONESEQ_8_INITIALIZER
-#define PCG16SI_INITIALIZER PCG_STATE_ONESEQ_16_INITIALIZER
-#define PCG32SI_INITIALIZER PCG_STATE_ONESEQ_32_INITIALIZER
-#define PCG64SI_INITIALIZER PCG_STATE_ONESEQ_64_INITIALIZER
-#if PCG_HAS_128BIT_OPS
-#define PCG128SI_INITIALIZER PCG_STATE_ONESEQ_128_INITIALIZER
-#endif
-
-#define PCG8I_INITIALIZER PCG_STATE_SETSEQ_8_INITIALIZER
-#define PCG16I_INITIALIZER PCG_STATE_SETSEQ_16_INITIALIZER
-#define PCG32I_INITIALIZER PCG_STATE_SETSEQ_32_INITIALIZER
-#define PCG64I_INITIALIZER PCG_STATE_SETSEQ_64_INITIALIZER
-#if PCG_HAS_128BIT_OPS
-#define PCG128I_INITIALIZER PCG_STATE_SETSEQ_128_INITIALIZER
-#endif
-
-#if __cplusplus
-}
-#endif
-
-#endif // PCG_VARIANTS_H_INCLUDED
diff --git a/numpy/random/src/philox/philox.c b/numpy/random/src/philox/philox.c
index 3382c60d6..6f2fad5a4 100644
--- a/numpy/random/src/philox/philox.c
+++ b/numpy/random/src/philox/philox.c
@@ -1,8 +1,8 @@
#include "philox.h"
-extern INLINE uint64_t philox_next64(philox_state *state);
+extern NPY_INLINE uint64_t philox_next64(philox_state *state);
-extern INLINE uint32_t philox_next32(philox_state *state);
+extern NPY_INLINE uint32_t philox_next32(philox_state *state);
extern void philox_jump(philox_state *state) {
/* Advances state as-if 2^128 draws were made */
diff --git a/numpy/random/src/philox/philox.h b/numpy/random/src/philox/philox.h
index 411404b55..ae6cf9308 100644
--- a/numpy/random/src/philox/philox.h
+++ b/numpy/random/src/philox/philox.h
@@ -2,12 +2,7 @@
#define _RANDOMDGEN__PHILOX_H_
#include <inttypes.h>
-
-#ifdef _WIN32
-#define INLINE __inline __forceinline
-#else
-#define INLINE inline
-#endif
+#include "numpy/npy_common.h"
#define PHILOX_BUFFER_SIZE 4L
@@ -23,7 +18,7 @@ typedef struct r123array4x64 philox4x64_ctr_t;
typedef struct r123array2x64 philox4x64_key_t;
typedef struct r123array2x64 philox4x64_ukey_t;
-static INLINE struct r123array2x64
+static NPY_INLINE struct r123array2x64
_philox4x64bumpkey(struct r123array2x64 key) {
key.v[0] += (0x9E3779B97F4A7C15ULL);
key.v[1] += (0xBB67AE8584CAA73BULL);
@@ -37,7 +32,7 @@ _philox4x64bumpkey(struct r123array2x64 key) {
#pragma intrinsic(_umul128)
#else
#pragma intrinsic(__emulu)
-static INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) {
+static NPY_INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) {
uint64_t a_lo, a_hi, b_lo, b_hi, a_x_b_hi, a_x_b_mid, a_x_b_lo, b_x_a_mid,
carry_bit;
@@ -60,18 +55,18 @@ static INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) {
return a_x_b_lo + ((a_x_b_mid + b_x_a_mid) << 32);
}
#endif
-static INLINE uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t *hip) {
+static NPY_INLINE uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t *hip) {
return _umul128(a, b, hip);
}
#else
#if __SIZEOF_INT128__
-static INLINE uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t *hip) {
+static NPY_INLINE uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t *hip) {
__uint128_t product = ((__uint128_t)a) * ((__uint128_t)b);
*hip = product >> 64;
return (uint64_t)product;
}
#else
-static INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) {
+static NPY_INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) {
uint64_t a_lo, a_hi, b_lo, b_hi, a_x_b_hi, a_x_b_mid, a_x_b_lo, b_x_a_mid,
carry_bit;
@@ -93,16 +88,16 @@ static INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) {
return a_x_b_lo + ((a_x_b_mid + b_x_a_mid) << 32);
}
-static INLINE uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t *hip) {
+static NPY_INLINE uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t *hip) {
return _umul128(a, b, hip);
}
#endif
#endif
-static INLINE struct r123array4x64 _philox4x64round(struct r123array4x64 ctr,
+static NPY_INLINE struct r123array4x64 _philox4x64round(struct r123array4x64 ctr,
struct r123array2x64 key);
-static INLINE struct r123array4x64 _philox4x64round(struct r123array4x64 ctr,
+static NPY_INLINE struct r123array4x64 _philox4x64round(struct r123array4x64 ctr,
struct r123array2x64 key) {
uint64_t hi0;
uint64_t hi1;
@@ -113,14 +108,14 @@ static INLINE struct r123array4x64 _philox4x64round(struct r123array4x64 ctr,
return out;
}
-static INLINE philox4x64_key_t philox4x64keyinit(philox4x64_ukey_t uk) {
+static NPY_INLINE philox4x64_key_t philox4x64keyinit(philox4x64_ukey_t uk) {
return uk;
}
-static INLINE philox4x64_ctr_t philox4x64_R(unsigned int R,
+static NPY_INLINE philox4x64_ctr_t philox4x64_R(unsigned int R,
philox4x64_ctr_t ctr,
philox4x64_key_t key);
-static INLINE philox4x64_ctr_t philox4x64_R(unsigned int R,
+static NPY_INLINE philox4x64_ctr_t philox4x64_R(unsigned int R,
philox4x64_ctr_t ctr,
philox4x64_key_t key) {
if (R > 0) {
@@ -198,7 +193,7 @@ typedef struct s_philox_state {
uint32_t uinteger;
} philox_state;
-static INLINE uint64_t philox_next(philox_state *state) {
+static NPY_INLINE uint64_t philox_next(philox_state *state) {
uint64_t out;
int i;
philox4x64_ctr_t ct;
@@ -228,11 +223,11 @@ static INLINE uint64_t philox_next(philox_state *state) {
return state->buffer[0];
}
-static INLINE uint64_t philox_next64(philox_state *state) {
+static NPY_INLINE uint64_t philox_next64(philox_state *state) {
return philox_next(state);
}
-static INLINE uint32_t philox_next32(philox_state *state) {
+static NPY_INLINE uint32_t philox_next32(philox_state *state) {
uint64_t next;
if (state->has_uint32) {
diff --git a/numpy/random/src/splitmix64/splitmix64.h b/numpy/random/src/splitmix64/splitmix64.h
index 880132970..d5877905e 100644
--- a/numpy/random/src/splitmix64/splitmix64.h
+++ b/numpy/random/src/splitmix64/splitmix64.h
@@ -1,13 +1,4 @@
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define inline __forceinline
-#else
#include <inttypes.h>
-#endif
-#else
-#include <inttypes.h>
-#endif
typedef struct s_splitmix64_state {
uint64_t state;
diff --git a/numpy/random/src/threefry/threefry.c b/numpy/random/src/threefry/threefry.c
index 19c37df1b..55d3c022a 100644
--- a/numpy/random/src/threefry/threefry.c
+++ b/numpy/random/src/threefry/threefry.c
@@ -1,8 +1,8 @@
#include "threefry.h"
-extern INLINE uint64_t threefry_next64(threefry_state *state);
+extern NPY_INLINE uint64_t threefry_next64(threefry_state *state);
-extern INLINE uint32_t threefry_next32(threefry_state *state);
+extern NPY_INLINE uint32_t threefry_next32(threefry_state *state);
extern void threefry_jump(threefry_state *state) {
/* Advances state as-if 2^128 draws were made */
diff --git a/numpy/random/src/threefry/threefry.h b/numpy/random/src/threefry/threefry.h
index 297c1241a..596b57e12 100644
--- a/numpy/random/src/threefry/threefry.h
+++ b/numpy/random/src/threefry/threefry.h
@@ -4,18 +4,8 @@ Adapted from random123's threefry.h
#ifndef _RANDOMDGEN__THREEFRY_H_
#define _RANDOMDGEN__THREEFRY_H_
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define INLINE __forceinline
-#else
#include <inttypes.h>
-#define INLINE __inline __forceinline
-#endif
-#else
-#include <inttypes.h>
-#define INLINE inline
-#endif
+#include "numpy/npy_common.h"
#define THREEFRY_BUFFER_SIZE 4L
@@ -47,15 +37,15 @@ struct r123array4x64 {
typedef struct r123array4x64 threefry4x64_key_t;
typedef struct r123array4x64 threefry4x64_ctr_t;
-static INLINE uint64_t RotL_64(uint64_t x, unsigned int N);
-static INLINE uint64_t RotL_64(uint64_t x, unsigned int N) {
+static NPY_INLINE uint64_t RotL_64(uint64_t x, unsigned int N);
+static NPY_INLINE uint64_t RotL_64(uint64_t x, unsigned int N) {
return (x << (N & 63)) | (x >> ((64 - N) & 63));
}
-static INLINE threefry4x64_ctr_t threefry4x64_R(unsigned int Nrounds,
+static NPY_INLINE threefry4x64_ctr_t threefry4x64_R(unsigned int Nrounds,
threefry4x64_ctr_t in,
threefry4x64_key_t k);
-static INLINE threefry4x64_ctr_t threefry4x64_R(unsigned int Nrounds,
+static NPY_INLINE threefry4x64_ctr_t threefry4x64_R(unsigned int Nrounds,
threefry4x64_ctr_t in,
threefry4x64_key_t k) {
threefry4x64_ctr_t X;
@@ -288,7 +278,7 @@ typedef struct s_threefry_state {
uint32_t uinteger;
} threefry_state;
-static INLINE uint64_t threefry_next(threefry_state *state) {
+static NPY_INLINE uint64_t threefry_next(threefry_state *state) {
int i;
threefry4x64_ctr_t ct;
uint64_t out;
@@ -317,11 +307,11 @@ static INLINE uint64_t threefry_next(threefry_state *state) {
return state->buffer[0];
}
-static INLINE uint64_t threefry_next64(threefry_state *state) {
+static NPY_INLINE uint64_t threefry_next64(threefry_state *state) {
return threefry_next(state);
}
-static INLINE uint32_t threefry_next32(threefry_state *state) {
+static NPY_INLINE uint32_t threefry_next32(threefry_state *state) {
uint64_t next;
if (state->has_uint32) {
state->has_uint32 = 0;
diff --git a/numpy/random/src/threefry32/threefry32.c b/numpy/random/src/threefry32/threefry32.c
index 500e9482d..cc6890f2e 100644
--- a/numpy/random/src/threefry32/threefry32.c
+++ b/numpy/random/src/threefry32/threefry32.c
@@ -1,8 +1,8 @@
#include "threefry32.h"
-extern INLINE uint64_t threefry32_next64(threefry32_state *state);
+extern NPY_INLINE uint64_t threefry32_next64(threefry32_state *state);
-extern INLINE uint32_t threefry32_next32(threefry32_state *state);
+extern NPY_INLINE uint32_t threefry32_next32(threefry32_state *state);
extern void threefry32_jump(threefry32_state *state) {
/* Advances state as-if 2^64 draws were made */
diff --git a/numpy/random/src/threefry32/threefry32.h b/numpy/random/src/threefry32/threefry32.h
index 74a85c42b..ebedee804 100644
--- a/numpy/random/src/threefry32/threefry32.h
+++ b/numpy/random/src/threefry32/threefry32.h
@@ -4,23 +4,13 @@ Adapted from random123's threefry.h
#ifndef _RANDOMDGEN__THREEFRY32_H_
#define _RANDOMDGEN__THREEFRY32_H_
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define INLINE __forceinline
-#else
#include <inttypes.h>
-#define INLINE __inline __forceinline
-#endif
-#else
-#include <inttypes.h>
-#define INLINE inline
-#endif
+#include "numpy/npy_common.h"
#define THREEFRY_BUFFER_SIZE 4L
-static INLINE uint32_t RotL_32(uint32_t x, unsigned int N);
-static INLINE uint32_t RotL_32(uint32_t x, unsigned int N) {
+static NPY_INLINE uint32_t RotL_32(uint32_t x, unsigned int N);
+static NPY_INLINE uint32_t RotL_32(uint32_t x, unsigned int N) {
return (x << (N & 31)) | (x >> ((32 - N) & 31));
}
@@ -52,13 +42,13 @@ enum r123_enum_threefry32x4 {
typedef struct r123array4x32 threefry4x32_ctr_t;
typedef struct r123array4x32 threefry4x32_key_t;
typedef struct r123array4x32 threefry4x32_ukey_t;
-static INLINE threefry4x32_key_t threefry4x32keyinit(threefry4x32_ukey_t uk) {
+static NPY_INLINE threefry4x32_key_t threefry4x32keyinit(threefry4x32_ukey_t uk) {
return uk;
};
-static INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
+static NPY_INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
threefry4x32_ctr_t in,
threefry4x32_key_t k);
-static INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
+static NPY_INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
threefry4x32_ctr_t in,
threefry4x32_key_t k) {
threefry4x32_ctr_t X;
@@ -779,9 +769,9 @@ static INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
return X;
}
enum r123_enum_threefry4x32 { threefry4x32_rounds = 20 };
-static INLINE threefry4x32_ctr_t threefry4x32(threefry4x32_ctr_t in,
+static NPY_INLINE threefry4x32_ctr_t threefry4x32(threefry4x32_ctr_t in,
threefry4x32_key_t k);
-static INLINE threefry4x32_ctr_t threefry4x32(threefry4x32_ctr_t in,
+static NPY_INLINE threefry4x32_ctr_t threefry4x32(threefry4x32_ctr_t in,
threefry4x32_key_t k) {
return threefry4x32_R(threefry4x32_rounds, in, k);
}
@@ -793,7 +783,7 @@ typedef struct s_threefry32_state {
uint32_t buffer[THREEFRY_BUFFER_SIZE];
} threefry32_state;
-static INLINE uint32_t threefry32_next(threefry32_state *state) {
+static NPY_INLINE uint32_t threefry32_next(threefry32_state *state) {
int i;
threefry4x32_ctr_t ct;
uint32_t out;
@@ -822,15 +812,15 @@ static INLINE uint32_t threefry32_next(threefry32_state *state) {
return state->buffer[0];
}
-static INLINE uint64_t threefry32_next64(threefry32_state *state) {
+static NPY_INLINE uint64_t threefry32_next64(threefry32_state *state) {
return ((uint64_t)threefry32_next(state) << 32) | threefry32_next(state);
}
-static INLINE uint32_t threefry32_next32(threefry32_state *state) {
+static NPY_INLINE uint32_t threefry32_next32(threefry32_state *state) {
return threefry32_next(state);
}
-static INLINE double threefry32_next_double(threefry32_state *state) {
+static NPY_INLINE double threefry32_next_double(threefry32_state *state) {
int32_t a = threefry32_next(state) >> 5, b = threefry32_next(state) >> 6;
return (a * 67108864.0 + b) / 9007199254740992.0;
}
diff --git a/numpy/random/src/xoroshiro128/xoroshiro128.c b/numpy/random/src/xoroshiro128/xoroshiro128.c
index 060eb8a51..baefcf3a8 100644
--- a/numpy/random/src/xoroshiro128/xoroshiro128.c
+++ b/numpy/random/src/xoroshiro128/xoroshiro128.c
@@ -31,9 +31,9 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
#include "xoroshiro128.h"
-extern INLINE uint64_t xoroshiro128_next64(xoroshiro128_state *state);
+extern NPY_INLINE uint64_t xoroshiro128_next64(xoroshiro128_state *state);
-extern INLINE uint32_t xoroshiro128_next32(xoroshiro128_state *state);
+extern NPY_INLINE uint32_t xoroshiro128_next32(xoroshiro128_state *state);
void xoroshiro128_jump(xoroshiro128_state *state)
{
diff --git a/numpy/random/src/xoroshiro128/xoroshiro128.h b/numpy/random/src/xoroshiro128/xoroshiro128.h
index 0db82b173..63682776b 100644
--- a/numpy/random/src/xoroshiro128/xoroshiro128.h
+++ b/numpy/random/src/xoroshiro128/xoroshiro128.h
@@ -1,18 +1,8 @@
#ifndef _RANDOMDGEN__XOROSHIRO128_H_
#define _RANDOMDGEN__XOROSHIRO128_H_
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define INLINE __forceinline
-#else
#include <inttypes.h>
-#define INLINE __inline __forceinline
-#endif
-#else
-#include <inttypes.h>
-#define INLINE inline
-#endif
+#include "numpy/npy_common.h"
typedef struct s_xoroshiro128_state
{
@@ -21,12 +11,12 @@ typedef struct s_xoroshiro128_state
uint32_t uinteger;
} xoroshiro128_state;
-static INLINE uint64_t rotl(const uint64_t x, int k)
+static NPY_INLINE uint64_t rotl(const uint64_t x, int k)
{
return (x << k) | (x >> (64 - k));
}
-static INLINE uint64_t xoroshiro128_next(uint64_t *s)
+static NPY_INLINE uint64_t xoroshiro128_next(uint64_t *s)
{
const uint64_t s0 = s[0];
uint64_t s1 = s[1];
@@ -39,12 +29,12 @@ static INLINE uint64_t xoroshiro128_next(uint64_t *s)
return result;
}
-static INLINE uint64_t xoroshiro128_next64(xoroshiro128_state *state)
+static NPY_INLINE uint64_t xoroshiro128_next64(xoroshiro128_state *state)
{
return xoroshiro128_next(&state->s[0]);
}
-static INLINE uint32_t xoroshiro128_next32(xoroshiro128_state *state)
+static NPY_INLINE uint32_t xoroshiro128_next32(xoroshiro128_state *state)
{
uint64_t next;
if (state->has_uint32)
diff --git a/numpy/random/src/xorshift1024/xorshift1024.c b/numpy/random/src/xorshift1024/xorshift1024.c
index 8737b5a82..d68ecc7d3 100644
--- a/numpy/random/src/xorshift1024/xorshift1024.c
+++ b/numpy/random/src/xorshift1024/xorshift1024.c
@@ -4,9 +4,9 @@
to 2^512 calls to next(); it can be used to generate 2^512
non-overlapping subsequences for parallel computations. */
-extern INLINE uint64_t xorshift1024_next(xorshift1024_state *state);
-extern INLINE uint64_t xorshift1024_next64(xorshift1024_state *state);
-extern INLINE uint32_t xorshift1024_next32(xorshift1024_state *state);
+extern NPY_INLINE uint64_t xorshift1024_next(xorshift1024_state *state);
+extern NPY_INLINE uint64_t xorshift1024_next64(xorshift1024_state *state);
+extern NPY_INLINE uint32_t xorshift1024_next32(xorshift1024_state *state);
void xorshift1024_jump(xorshift1024_state *state) {
int i, j, b;
diff --git a/numpy/random/src/xorshift1024/xorshift1024.h b/numpy/random/src/xorshift1024/xorshift1024.h
index e0ef77826..38ec27430 100644
--- a/numpy/random/src/xorshift1024/xorshift1024.h
+++ b/numpy/random/src/xorshift1024/xorshift1024.h
@@ -1,18 +1,8 @@
#ifndef _RANDOMDGEN__XORSHIFT1024_H_
#define _RANDOMDGEN__XORSHIFT1024_H_
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define INLINE __forceinline
-#else
#include <inttypes.h>
-#define INLINE __inline __forceinline
-#endif
-#else
-#include <inttypes.h>
-#define INLINE inline
-#endif
+#include "numpy/npy_common.h"
typedef struct s_xorshift1024_state {
uint64_t s[16];
@@ -21,7 +11,7 @@ typedef struct s_xorshift1024_state {
uint32_t uinteger;
} xorshift1024_state;
-static INLINE uint64_t xorshift1024_next(xorshift1024_state *state) {
+static NPY_INLINE uint64_t xorshift1024_next(xorshift1024_state *state) {
const uint64_t s0 = state->s[state->p];
uint64_t s1 = state->s[state->p = ((state->p) + 1) & 15];
s1 ^= s1 << 31; // a
@@ -29,11 +19,11 @@ static INLINE uint64_t xorshift1024_next(xorshift1024_state *state) {
return state->s[state->p] * 0x9e3779b97f4a7c13;
}
-static INLINE uint64_t xorshift1024_next64(xorshift1024_state *state) {
+static NPY_INLINE uint64_t xorshift1024_next64(xorshift1024_state *state) {
return xorshift1024_next(state);
}
-static INLINE uint32_t xorshift1024_next32(xorshift1024_state *state) {
+static NPY_INLINE uint32_t xorshift1024_next32(xorshift1024_state *state) {
uint64_t next;
if (state->has_uint32) {
state->has_uint32 = 0;
diff --git a/numpy/random/src/xoshiro256starstar/LICENSE.md b/numpy/random/src/xoshiro256/LICENSE.md
index d863f3b29..d863f3b29 100644
--- a/numpy/random/src/xoshiro256starstar/LICENSE.md
+++ b/numpy/random/src/xoshiro256/LICENSE.md
diff --git a/numpy/random/src/xoshiro256starstar/xoshiro256starstar-test-data-gen.c b/numpy/random/src/xoshiro256/xoshiro256-test-data-gen.c
index 8522229dd..94eeb7346 100644
--- a/numpy/random/src/xoshiro256starstar/xoshiro256starstar-test-data-gen.c
+++ b/numpy/random/src/xoshiro256/xoshiro256-test-data-gen.c
@@ -1,13 +1,13 @@
/*
* Generate testing csv files
*
- * cl xoshiro256starstar-test-data-gen.c xoshiro256starstar.orig.c /
+ * cl xoshiro256-test-data-gen.c xoshiro256.orig.c /
* ../splitmix64/splitmix64.c /Ox
- * xoshiro256starstar-test-data-gen.exe *
+ * xoshiro256-test-data-gen.exe *
*
- * gcc xoshiro256starstar-test-data-gen.c xoshiro256starstar.orig.c /
- * ../splitmix64/splitmix64.c -o xoshiro256starstar-test-data-gen
- * ./xoshiro256starstar-test-data-gen
+ * gcc xoshiro256-test-data-gen.c xoshiro256.orig.c /
+ * ../splitmix64/splitmix64.c -o xoshiro256-test-data-gen
+ * ./xoshiro256-test-data-gen
*
* Requres the Random123 directory containing header files to be located in the
* same directory (not included).
@@ -15,7 +15,7 @@
*/
#include "../splitmix64/splitmix64.h"
-#include "xoshiro256starstar.orig.h"
+#include "xoshiro256.orig.h"
#include <inttypes.h>
#include <stdio.h>
@@ -35,7 +35,7 @@ int main() {
}
FILE *fp;
- fp = fopen("xoshiro256starstar-testset-1.csv", "w");
+ fp = fopen("xoshiro256-testset-1.csv", "w");
if (fp == NULL) {
printf("Couldn't open file\n");
return -1;
@@ -56,7 +56,7 @@ int main() {
for (i = 0; i < N; i++) {
store[i] = next();
}
- fp = fopen("xoshiro256starstar-testset-2.csv", "w");
+ fp = fopen("xoshiro256-testset-2.csv", "w");
if (fp == NULL) {
printf("Couldn't open file\n");
return -1;
diff --git a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.c b/numpy/random/src/xoshiro256/xoshiro256.c
index 30b6c7d85..f5cda2721 100644
--- a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.c
+++ b/numpy/random/src/xoshiro256/xoshiro256.c
@@ -6,7 +6,7 @@ worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
-#include "xoshiro256starstar.h"
+#include "xoshiro256.h"
/* This is xoshiro256** 1.0, our all-purpose, rock-solid generator. It has
excellent (sub-ns) speed, a state (256 bits) that is large enough for
@@ -18,15 +18,16 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
output to fill s. */
-extern INLINE uint64_t xoshiro256starstar_next64(xoshiro256starstar_state *state);
+extern NPY_INLINE uint64_t xoshiro256_next64(xoshiro256_state *state);
+
+extern NPY_INLINE uint32_t xoshiro256_next32(xoshiro256_state *state);
-extern INLINE uint32_t xoshiro256starstar_next32(xoshiro256starstar_state *state);
/* This is the jump function for the generator. It is equivalent
to 2^128 calls to next(); it can be used to generate 2^128
non-overlapping subsequences for parallel computations. */
-void xoshiro256starstar_jump(xoshiro256starstar_state *state)
+void xoshiro256_jump(xoshiro256_state *state)
{
int i, b;
static const uint64_t JUMP[] = {0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c};
@@ -45,7 +46,7 @@ void xoshiro256starstar_jump(xoshiro256starstar_state *state)
s2 ^= state->s[2];
s3 ^= state->s[3];
}
- xoshiro256starstar_next(&state->s[0]);
+ xoshiro256_next(&state->s[0]);
}
state->s[0] = s0;
diff --git a/numpy/random/src/xoshiro256/xoshiro256.h b/numpy/random/src/xoshiro256/xoshiro256.h
new file mode 100644
index 000000000..1908245a5
--- /dev/null
+++ b/numpy/random/src/xoshiro256/xoshiro256.h
@@ -0,0 +1,53 @@
+#ifndef _RANDOMDGEN__XOSHIRO256STARSTAR_H_
+#define _RANDOMDGEN__XOSHIRO256STARSTAR_H_
+
+#include <inttypes.h>
+#include "numpy/npy_common.h"
+
+typedef struct s_xoshiro256_state {
+ uint64_t s[4];
+ int has_uint32;
+ uint32_t uinteger;
+} xoshiro256_state;
+
+static NPY_INLINE uint64_t rotl(const uint64_t x, int k) {
+ return (x << k) | (x >> (64 - k));
+}
+
+static NPY_INLINE uint64_t xoshiro256_next(uint64_t *s) {
+ const uint64_t result_starstar = rotl(s[1] * 5, 7) * 9;
+ const uint64_t t = s[1] << 17;
+
+ s[2] ^= s[0];
+ s[3] ^= s[1];
+ s[1] ^= s[2];
+ s[0] ^= s[3];
+
+ s[2] ^= t;
+
+ s[3] = rotl(s[3], 45);
+
+ return result_starstar;
+}
+
+
+static NPY_INLINE uint64_t xoshiro256_next64(xoshiro256_state *state) {
+ return xoshiro256_next(&state->s[0]);
+}
+
+static NPY_INLINE uint32_t xoshiro256_next32(xoshiro256_state *state) {
+
+ uint64_t next;
+ if (state->has_uint32) {
+ state->has_uint32 = 0;
+ return state->uinteger;
+ }
+ next = xoshiro256_next(&state->s[0]);
+ state->has_uint32 = 1;
+ state->uinteger = (uint32_t)(next >> 32);
+ return (uint32_t)(next & 0xffffffff);
+}
+
+void xoshiro256_jump(xoshiro256_state *state);
+
+#endif
diff --git a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.orig.c b/numpy/random/src/xoshiro256/xoshiro256.orig.c
index ecf87bab9..ecf87bab9 100644
--- a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.orig.c
+++ b/numpy/random/src/xoshiro256/xoshiro256.orig.c
diff --git a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.orig.h b/numpy/random/src/xoshiro256/xoshiro256.orig.h
index 3aa788ec9..3aa788ec9 100644
--- a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.orig.h
+++ b/numpy/random/src/xoshiro256/xoshiro256.orig.h
diff --git a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.h b/numpy/random/src/xoshiro256starstar/xoshiro256starstar.h
deleted file mode 100644
index 1d7d8ea40..000000000
--- a/numpy/random/src/xoshiro256starstar/xoshiro256starstar.h
+++ /dev/null
@@ -1,63 +0,0 @@
-#ifndef _RANDOMDGEN__XOSHIRO256STARSTAR_H_
-#define _RANDOMDGEN__XOSHIRO256STARSTAR_H_
-
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define INLINE __forceinline
-#else
-#include <inttypes.h>
-#define INLINE __inline __forceinline
-#endif
-#else
-#include <inttypes.h>
-#define INLINE inline
-#endif
-
-typedef struct s_xoshiro256starstar_state {
- uint64_t s[4];
- int has_uint32;
- uint32_t uinteger;
-} xoshiro256starstar_state;
-
-static INLINE uint64_t rotl(const uint64_t x, int k) {
- return (x << k) | (x >> (64 - k));
-}
-
-static INLINE uint64_t xoshiro256starstar_next(uint64_t *s) {
- const uint64_t result_starstar = rotl(s[1] * 5, 7) * 9;
- const uint64_t t = s[1] << 17;
-
- s[2] ^= s[0];
- s[3] ^= s[1];
- s[1] ^= s[2];
- s[0] ^= s[3];
-
- s[2] ^= t;
-
- s[3] = rotl(s[3], 45);
-
- return result_starstar;
-}
-
-static INLINE uint64_t
-xoshiro256starstar_next64(xoshiro256starstar_state *state) {
- return xoshiro256starstar_next(&state->s[0]);
-}
-
-static INLINE uint32_t
-xoshiro256starstar_next32(xoshiro256starstar_state *state) {
- uint64_t next;
- if (state->has_uint32) {
- state->has_uint32 = 0;
- return state->uinteger;
- }
- next = xoshiro256starstar_next(&state->s[0]);
- state->has_uint32 = 1;
- state->uinteger = (uint32_t)(next >> 32);
- return (uint32_t)(next & 0xffffffff);
-}
-
-void xoshiro256starstar_jump(xoshiro256starstar_state *state);
-
-#endif
diff --git a/numpy/random/src/xoshiro512starstar/LICENSE.md b/numpy/random/src/xoshiro512/LICENSE.md
index aa34c1966..aa34c1966 100644
--- a/numpy/random/src/xoshiro512starstar/LICENSE.md
+++ b/numpy/random/src/xoshiro512/LICENSE.md
diff --git a/numpy/random/src/xoshiro512starstar/xoshiro512starstar-test-data-gen.c b/numpy/random/src/xoshiro512/xoshiro512-test-data-gen.c
index bcc3574e4..83e164a51 100644
--- a/numpy/random/src/xoshiro512starstar/xoshiro512starstar-test-data-gen.c
+++ b/numpy/random/src/xoshiro512/xoshiro512-test-data-gen.c
@@ -1,13 +1,13 @@
/*
* Generate testing csv files
*
- * cl xoshiro512starstar-test-data-gen.c xoshiro512starstar.orig.c /
+ * cl xoshiro512-test-data-gen.c xoshiro512.orig.c /
* ../splitmix64/splitmix64.c /Ox
- * xoshiro512starstar-test-data-gen.exe *
+ * xoshiro512-test-data-gen.exe *
*
- * gcc xoshiro512starstar-test-data-gen.c xoshiro512starstar.orig.c /
- * ../splitmix64/splitmix64.c -o xoshiro512starstar-test-data-gen
- * ./xoshiro512starstar-test-data-gen
+ * gcc xoshiro512-test-data-gen.c xoshiro512.orig.c /
+ * ../splitmix64/splitmix64.c -o xoshiro512-test-data-gen
+ * ./xoshiro512-test-data-gen
*
* Requres the Random123 directory containing header files to be located in the
* same directory (not included).
@@ -15,7 +15,7 @@
*/
#include "../splitmix64/splitmix64.h"
-#include "xoshiro512starstar.orig.h"
+#include "xoshiro512.orig.h"
#include <inttypes.h>
#include <stdio.h>
@@ -35,7 +35,7 @@ int main() {
}
FILE *fp;
- fp = fopen("xoshiro512starstar-testset-1.csv", "w");
+ fp = fopen("xoshiro512-testset-1.csv", "w");
if (fp == NULL) {
printf("Couldn't open file\n");
return -1;
@@ -56,7 +56,7 @@ int main() {
for (i = 0; i < N; i++) {
store[i] = next();
}
- fp = fopen("xoshiro512starstar-testset-2.csv", "w");
+ fp = fopen("xoshiro512-testset-2.csv", "w");
if (fp == NULL) {
printf("Couldn't open file\n");
return -1;
diff --git a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.c b/numpy/random/src/xoshiro512/xoshiro512.c
index a9f56699f..9fdbed125 100644
--- a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.c
+++ b/numpy/random/src/xoshiro512/xoshiro512.c
@@ -6,7 +6,7 @@ worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
-#include "xoshiro512starstar.h"
+#include "xoshiro512.h"
/* This is xoshiro512** 1.0, an all-purpose, rock-solid generator. It has
excellent (about 1ns) speed, an increased state (512 bits) that is
@@ -19,11 +19,10 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
output to fill s. */
-extern INLINE uint64_t
-xoshiro512starstar_next64(xoshiro512starstar_state *state);
+extern NPY_INLINE uint64_t xoshiro512_next64(xoshiro512_state *state);
+
+extern NPY_INLINE uint32_t xoshiro512_next32(xoshiro512_state *state);
-extern INLINE uint32_t
-xoshiro512starstar_next32(xoshiro512starstar_state *state);
/* This is the jump function for the generator. It is equivalent
to 2^256 calls to next(); it can be used to generate 2^256
@@ -31,7 +30,7 @@ xoshiro512starstar_next32(xoshiro512starstar_state *state);
static uint64_t s_placeholder[8];
-void xoshiro512starstar_jump(xoshiro512starstar_state *state) {
+void xoshiro512_jump(xoshiro512_state *state) {
int i, b, w;
static const uint64_t JUMP[] = {0x33ed89b6e7a353f9, 0x760083d7955323be,
@@ -46,7 +45,7 @@ void xoshiro512starstar_jump(xoshiro512starstar_state *state) {
if (JUMP[i] & UINT64_C(1) << b)
for (w = 0; w < sizeof s_placeholder / sizeof *s_placeholder; w++)
t[w] ^= state->s[w];
- xoshiro512starstar_next(&state->s[0]);
+ xoshiro512_next(&state->s[0]);
}
memcpy(state->s, t, sizeof s_placeholder);
diff --git a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.h b/numpy/random/src/xoshiro512/xoshiro512.h
index 0fa0ba3cd..6ce6c7db7 100644
--- a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.h
+++ b/numpy/random/src/xoshiro512/xoshiro512.h
@@ -1,33 +1,23 @@
#ifndef _RANDOMDGEN__XOSHIRO512STARSTAR_H_
#define _RANDOMDGEN__XOSHIRO512STARSTAR_H_
-#ifdef _WIN32
-#if _MSC_VER == 1500
-#include "../common/inttypes.h"
-#define INLINE __forceinline
-#else
-#include <inttypes.h>
-#define INLINE __inline __forceinline
-#endif
-#else
-#include <inttypes.h>
-#define INLINE inline
-#endif
#include <string.h>
+#include <inttypes.h>
+#include "numpy/npy_common.h"
-typedef struct s_xoshiro512starstar_state
+typedef struct s_xoshiro512_state
{
uint64_t s[8];
int has_uint32;
uint32_t uinteger;
-} xoshiro512starstar_state;
+} xoshiro512_state;
-static INLINE uint64_t rotl(const uint64_t x, int k)
+static NPY_INLINE uint64_t rotl(const uint64_t x, int k)
{
return (x << k) | (x >> (64 - k));
}
-static INLINE uint64_t xoshiro512starstar_next(uint64_t *s)
+static NPY_INLINE uint64_t xoshiro512_next(uint64_t *s)
{
const uint64_t result_starstar = rotl(s[1] * 5, 7) * 9;
@@ -49,14 +39,13 @@ static INLINE uint64_t xoshiro512starstar_next(uint64_t *s)
return result_starstar;
}
-static INLINE uint64_t
-xoshiro512starstar_next64(xoshiro512starstar_state *state)
+
+static NPY_INLINE uint64_t xoshiro512_next64(xoshiro512_state *state)
{
- return xoshiro512starstar_next(&state->s[0]);
+ return xoshiro512_next(&state->s[0]);
}
-static INLINE uint32_t
-xoshiro512starstar_next32(xoshiro512starstar_state *state)
+static NPY_INLINE uint32_t xoshiro512_next32(xoshiro512_state *state)
{
uint64_t next;
if (state->has_uint32)
@@ -64,12 +53,12 @@ xoshiro512starstar_next32(xoshiro512starstar_state *state)
state->has_uint32 = 0;
return state->uinteger;
}
- next = xoshiro512starstar_next(&state->s[0]);
+ next = xoshiro512_next(&state->s[0]);
state->has_uint32 = 1;
state->uinteger = (uint32_t)(next >> 32);
return (uint32_t)(next & 0xffffffff);
}
-void xoshiro512starstar_jump(xoshiro512starstar_state *state);
+void xoshiro512_jump(xoshiro512_state *state);
#endif
diff --git a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.orig.c b/numpy/random/src/xoshiro512/xoshiro512.orig.c
index 0cf884edb..ecdf81fc1 100644
--- a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.orig.c
+++ b/numpy/random/src/xoshiro512/xoshiro512.orig.c
@@ -6,7 +6,7 @@ worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
-#include "xoshiro512starstar.orig.h"
+#include "xoshiro512.orig.h"
/* This is xoshiro512** 1.0, an all-purpose, rock-solid generator. It has
excellent (about 1ns) speed, an increased state (512 bits) that is
diff --git a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.orig.h b/numpy/random/src/xoshiro512/xoshiro512.orig.h
index 0b7892473..0b7892473 100644
--- a/numpy/random/src/xoshiro512starstar/xoshiro512starstar.orig.h
+++ b/numpy/random/src/xoshiro512/xoshiro512.orig.h
diff --git a/numpy/random/tests/data/pcg32-testset-1.csv b/numpy/random/tests/data/pcg32-testset-1.csv
deleted file mode 100644
index 6bddc8d5c..000000000
--- a/numpy/random/tests/data/pcg32-testset-1.csv
+++ /dev/null
@@ -1,1001 +0,0 @@
-seed, 0xdeadbeaf
-0, 0xbeb77374
-1, 0x75cad014
-2, 0xabc6773e
-3, 0xe99a034e
-4, 0x1e3f5c6d
-5, 0x513d3c5b
-6, 0x4a378bad
-7, 0xba5b3488
-8, 0x21e96448
-9, 0x5197a3d3
-10, 0x84bbcc90
-11, 0x674fce76
-12, 0xd1dd9879
-13, 0x1625afd4
-14, 0x4bb5e330
-15, 0x3f4b8f74
-16, 0xf0a7c00b
-17, 0xecdb92d0
-18, 0xf069232c
-19, 0x56dbeaa2
-20, 0x70c62231
-21, 0x6c68e57e
-22, 0x3829213c
-23, 0x9b8bc5e6
-24, 0x45abd553
-25, 0xf5991ce7
-26, 0xb4aff20a
-27, 0x677a5785
-28, 0x108f180d
-29, 0x2b3f1001
-30, 0x838fdfcb
-31, 0x8ad3c2a0
-32, 0x596268fa
-33, 0xee6bcc56
-34, 0x46810af0
-35, 0x1648a587
-36, 0x7265a926
-37, 0xed0f3acc
-38, 0x72a1ac0
-39, 0xb3f7109f
-40, 0x6ddd75f2
-41, 0xa968127f
-42, 0x40df20fd
-43, 0xde835b80
-44, 0xe453cd68
-45, 0x26ad68eb
-46, 0x23a052d2
-47, 0x17881c5c
-48, 0x785d41b9
-49, 0x61b4530a
-50, 0x5ee92c84
-51, 0x4cad7358
-52, 0x843db584
-53, 0x3576368b
-54, 0x14db6b2b
-55, 0xb6e8b042
-56, 0x6323e866
-57, 0x9a709e25
-58, 0xae594bdc
-59, 0x4be9ec1b
-60, 0x77b4fd05
-61, 0x4421667
-62, 0x24bf98f7
-63, 0xfb202aed
-64, 0x2f01b05f
-65, 0xac766e69
-66, 0xc1572ce2
-67, 0xb26354d6
-68, 0x4db5f193
-69, 0x41a4609b
-70, 0x26bbb4cc
-71, 0x676b7438
-72, 0x13b2be7d
-73, 0x7df521c4
-74, 0x57f770f3
-75, 0x78a8a8
-76, 0x164d46c6
-77, 0xbb29da20
-78, 0x5c262bf9
-79, 0xfd305d0
-80, 0xb500d90b
-81, 0xbb7b4e37
-82, 0x5ba2bbfd
-83, 0xa9561043
-84, 0xe175c662
-85, 0x3a5c8eec
-86, 0xac5e2184
-87, 0x1e1c7de7
-88, 0x46be092a
-89, 0x8b82f5be
-90, 0xb1c1b591
-91, 0x6f06d957
-92, 0x1d26dc5c
-93, 0x158c57e3
-94, 0x6da1ebf8
-95, 0x74501e60
-96, 0x70587043
-97, 0xa19b90fe
-98, 0x7d327dff
-99, 0x22dc6b90
-100, 0xf48a9ae6
-101, 0x75eeb769
-102, 0x9cdc12cb
-103, 0x7fe2cdc6
-104, 0x4fba8066
-105, 0x1a7a0667
-106, 0xd9289d22
-107, 0x3a045bce
-108, 0x60e5f71f
-109, 0xd81b35dc
-110, 0xceae6194
-111, 0xa032a688
-112, 0x7157b327
-113, 0x61c74c80
-114, 0x2d519c39
-115, 0x5b1a352e
-116, 0x5ad266da
-117, 0x9118352b
-118, 0xdd20b6e1
-119, 0xc0d154fa
-120, 0x93bbb9c9
-121, 0x91170de2
-122, 0xa3af5e05
-123, 0x1b19ff2f
-124, 0xf814c3bf
-125, 0x8914a953
-126, 0x5278efb7
-127, 0x3c96d7bd
-128, 0xb5422a7
-129, 0x2aee2619
-130, 0x60c6a90c
-131, 0xfbec0e9c
-132, 0xef794075
-133, 0xda93d22e
-134, 0xb956d02a
-135, 0xd97cc49b
-136, 0x80737244
-137, 0x7c56a95
-138, 0xa5311355
-139, 0x7dcdd592
-140, 0x92add23e
-141, 0xb1ba1317
-142, 0x507e5330
-143, 0x2644b95a
-144, 0xa1afa519
-145, 0x596c65c0
-146, 0x6f47dd11
-147, 0xfd2fbada
-148, 0x98675d7c
-149, 0xb9e21413
-150, 0x8bae5eca
-151, 0xe1f50018
-152, 0x7dd08715
-153, 0x36a888e1
-154, 0x7fcd6364
-155, 0xb84c093
-156, 0x18e2d58f
-157, 0x19fd21ed
-158, 0x3c25e3a3
-159, 0x7a0d833b
-160, 0x47525b28
-161, 0xba88474
-162, 0xd108e7da
-163, 0x32b06660
-164, 0xbce027b3
-165, 0x96b31787
-166, 0x916ab263
-167, 0xa5fa088
-168, 0x3cb9cd59
-169, 0x7a97051f
-170, 0x104b6883
-171, 0x6e08c314
-172, 0x33a4c62c
-173, 0x14eb854
-174, 0x873f730a
-175, 0x8c3f7224
-176, 0x9a41beeb
-177, 0xe4e2ab0a
-178, 0xfa89ad0e
-179, 0x4aa62ac3
-180, 0xb75dc1bf
-181, 0x3f4c5131
-182, 0x3fef0f91
-183, 0xffa06655
-184, 0x417d7d38
-185, 0x1e7734df
-186, 0x25685235
-187, 0x33fe5b68
-188, 0x68923f72
-189, 0x5da45ff
-190, 0xb871df26
-191, 0xd3ffd8c6
-192, 0x1718d862
-193, 0xe127d844
-194, 0xadcdc48a
-195, 0x79ee30cb
-196, 0x931a6cba
-197, 0x9463c42d
-198, 0x9f8d2806
-199, 0xa3695a97
-200, 0xfc9587bc
-201, 0xb3943573
-202, 0x50ed8901
-203, 0x6891f33
-204, 0xb7a12dfb
-205, 0x1245cf5d
-206, 0xbc0f73a7
-207, 0x26cbfeb2
-208, 0x774d8e83
-209, 0xa19e9c1
-210, 0xc147a437
-211, 0xe034f2a3
-212, 0xd288b664
-213, 0xdcd0356d
-214, 0x2b695901
-215, 0x3bc31736
-216, 0x4a5b1998
-217, 0x18537410
-218, 0x11b40f35
-219, 0xf16f6f89
-220, 0xe844cffe
-221, 0xce026166
-222, 0x3770aaba
-223, 0xc62566ee
-224, 0x6db2d1f8
-225, 0xe4720b6d
-226, 0x68321a69
-227, 0x488539ac
-228, 0x5e18ab61
-229, 0xb58e598e
-230, 0x6f501a91
-231, 0xc4fd3e8d
-232, 0x9faa3631
-233, 0x184366b0
-234, 0xecf74d6a
-235, 0x3773d622
-236, 0x382ca536
-237, 0x93451381
-238, 0x9f148ed5
-239, 0x2b66f241
-240, 0xa6807c39
-241, 0xbb087446
-242, 0xa18ba432
-243, 0x8e7a6013
-244, 0xab30278e
-245, 0xbf457c78
-246, 0xb24814b1
-247, 0x710f99d5
-248, 0xbcb84762
-249, 0x4913a7e7
-250, 0x90a31a0c
-251, 0x6d4b1673
-252, 0x18873994
-253, 0x1efd517a
-254, 0x99b499d1
-255, 0x2d488776
-256, 0x1cded201
-257, 0xa53b02e4
-258, 0xcb20d0fd
-259, 0x72bfaae3
-260, 0x858c865b
-261, 0x2e2d3e96
-262, 0x8bc5b0b9
-263, 0x8980346a
-264, 0xa8e47fba
-265, 0x2a39fe16
-266, 0x9f34eeeb
-267, 0x7baebcc9
-268, 0xbc0b8d74
-269, 0x37373c8
-270, 0xe128cfc4
-271, 0x49cdb150
-272, 0x5965c726
-273, 0xfc326226
-274, 0x53a3e8e
-275, 0xa99d89f7
-276, 0x33ac111c
-277, 0x143fe678
-278, 0x96212281
-279, 0x6a83bffd
-280, 0x529852f7
-281, 0x97fef4
-282, 0x303ce151
-283, 0x4f8c7b83
-284, 0xd5ef9c82
-285, 0xede9d572
-286, 0xc03e2c38
-287, 0x89d7f886
-288, 0x21e998b0
-289, 0x58d505cf
-290, 0x5c42089
-291, 0x9a01dcab
-292, 0x83d8cc17
-293, 0x7d6aacf
-294, 0xa1cbdced
-295, 0x47365e25
-296, 0xbb61e976
-297, 0xfeafd0a6
-298, 0x760d82b4
-299, 0x9ffb351d
-300, 0x28e19ac0
-301, 0x891131c6
-302, 0xc1656522
-303, 0x4536d90
-304, 0x956b1b84
-305, 0xf9ff54f6
-306, 0xb0050d88
-307, 0x7d7fafa2
-308, 0x430e670b
-309, 0x18ad450d
-310, 0xd5a1d6b6
-311, 0x390a6da4
-312, 0xc70d557d
-313, 0xd8fadb5e
-314, 0xfb4b4cb6
-315, 0xce707f8b
-316, 0x4c18d350
-317, 0x8dc0d200
-318, 0x228d9e85
-319, 0xd6485ba3
-320, 0x37c4a70a
-321, 0x9d7cc5f5
-322, 0x889a9b9
-323, 0x41d2f942
-324, 0x4c13b3bd
-325, 0x70e58147
-326, 0x4a0e1270
-327, 0x3cdc1b73
-328, 0x7a4e56f3
-329, 0xd8350406
-330, 0x46068108
-331, 0xfc4da48
-332, 0xf6111245
-333, 0x40a15167
-334, 0x38a591ac
-335, 0x3e97e682
-336, 0x5c515d2d
-337, 0x45023a37
-338, 0xacb0ed6a
-339, 0x899f0ebb
-340, 0x2054df01
-341, 0x6d629607
-342, 0x79ced597
-343, 0xba0a3a12
-344, 0xde63b611
-345, 0x228cb776
-346, 0x61f10dba
-347, 0x9a1095d3
-348, 0xf08dcb3
-349, 0x88e58009
-350, 0x131880aa
-351, 0xc55002ee
-352, 0xcf556f47
-353, 0x17b6dd76
-354, 0x6110ba20
-355, 0x74a91935
-356, 0xe83cf9ed
-357, 0x3138e936
-358, 0x103bfb72
-359, 0x2084abe4
-360, 0xf3a05dd9
-361, 0x9213f3a4
-362, 0xe7674dd7
-363, 0xcd09d629
-364, 0x260461f2
-365, 0x411c2428
-366, 0xbb5f6f2e
-367, 0x6feb8c93
-368, 0x3cde3ece
-369, 0x7a424d2c
-370, 0x808a0948
-371, 0x653c3fdf
-372, 0x26f88849
-373, 0xf540b6ae
-374, 0x1f82e8ac
-375, 0x300f7e39
-376, 0xb6e62e7b
-377, 0x970441a1
-378, 0x91f2946c
-379, 0xaad281f
-380, 0x43be1dcf
-381, 0x95a1b4c8
-382, 0x2d956dea
-383, 0xc532ca29
-384, 0xc93f1fcf
-385, 0x70762aab
-386, 0x231a72ef
-387, 0xe5bd1b75
-388, 0xfa31468
-389, 0x77e1b7b5
-390, 0x19d80215
-391, 0xd45704b7
-392, 0x33472a0d
-393, 0x833a435e
-394, 0x2354a326
-395, 0x8af39828
-396, 0x603a7960
-397, 0x288c2d54
-398, 0x75bd7c23
-399, 0xe2dd42e1
-400, 0x9a87b486
-401, 0x32e9bcd1
-402, 0x8630f74f
-403, 0x160408ea
-404, 0xd2127c63
-405, 0xaf327f8e
-406, 0x8d879a61
-407, 0xc5c88f60
-408, 0x53a19fa1
-409, 0x706dacb4
-410, 0xd04ea0f
-411, 0x94806c1a
-412, 0x941cfe69
-413, 0x956a5562
-414, 0xee1f71c
-415, 0xe6ba12d
-416, 0x333e31f6
-417, 0x17aee12e
-418, 0x20ccfedb
-419, 0xd7bb7f92
-420, 0xba7d14f3
-421, 0xb935d4fb
-422, 0xbdb8f5e1
-423, 0xb24e7adc
-424, 0xc9abef71
-425, 0x3e3d8125
-426, 0x5fc0878b
-427, 0x5ba172d9
-428, 0xe28f648c
-429, 0x5137f3a7
-430, 0xb57273df
-431, 0xe68df236
-432, 0xbc29802b
-433, 0xb1419e66
-434, 0x69ecb739
-435, 0x490e8eb6
-436, 0x61e25a6c
-437, 0xc1fa0de6
-438, 0x2bf2fbf1
-439, 0x9487e8da
-440, 0xce5c5532
-441, 0x75859040
-442, 0x2606bdeb
-443, 0x1b77c072
-444, 0xe5fbeed1
-445, 0xea9e1ab3
-446, 0x55cf96ae
-447, 0x283ed27d
-448, 0xc94067a1
-449, 0x8687b3e5
-450, 0x4031b307
-451, 0xc5790e82
-452, 0x4031ee7f
-453, 0x952c4503
-454, 0x379ec606
-455, 0x7c35e19d
-456, 0x2d333769
-457, 0xbca36d54
-458, 0xcdc70741
-459, 0xa3ab56fb
-460, 0x187a2fd6
-461, 0xdd1f32f1
-462, 0xc007ac56
-463, 0x14c441c1
-464, 0xf290ed47
-465, 0xc833edac
-466, 0x13f0a8fe
-467, 0x63c10b6e
-468, 0x6af1be34
-469, 0x5bd4930e
-470, 0xfe56bfbb
-471, 0x1b412c8e
-472, 0xf0c7712a
-473, 0xf3a96226
-474, 0xbd0aaad8
-475, 0xbd00355e
-476, 0x8ba9eca1
-477, 0x81f136a0
-478, 0x7de3a327
-479, 0x7be298ea
-480, 0xe60e320a
-481, 0xaf4373b
-482, 0x6eacbf3
-483, 0x1291760f
-484, 0xd48ed89b
-485, 0x596603d4
-486, 0x53abc8
-487, 0x82123b2f
-488, 0x1276dc8
-489, 0xfeb474bb
-490, 0x4013da51
-491, 0x111cb9d6
-492, 0x5726df82
-493, 0x45806861
-494, 0x2580801a
-495, 0x1326049e
-496, 0xb9474bf9
-497, 0x6c5d85ed
-498, 0x9c4a9352
-499, 0x9eb915ed
-500, 0x914505
-501, 0xd14c5b9a
-502, 0x57ef8ffd
-503, 0x480d8719
-504, 0xb18d7fce
-505, 0xfd29e178
-506, 0x2679f6c9
-507, 0xd94a086e
-508, 0x6e46f559
-509, 0xb7c3a2e3
-510, 0x793a4c3b
-511, 0x4e5252f9
-512, 0x1bdb53a4
-513, 0xbed5794
-514, 0x31a3ebc7
-515, 0xa6eb54e1
-516, 0xc6ae5d92
-517, 0x392acfc8
-518, 0xb283fb8f
-519, 0x80b15ffe
-520, 0x763b49a8
-521, 0x3febc1d3
-522, 0x60f2b20
-523, 0xd93aeba9
-524, 0xeddf06bb
-525, 0x13992ab3
-526, 0x4521bcf6
-527, 0x5ad82a14
-528, 0xf2bfc79c
-529, 0xf664b9b
-530, 0xeb9540a2
-531, 0x5641dc50
-532, 0x9282d9c4
-533, 0x5d2443a4
-534, 0x407b5011
-535, 0x84a415d7
-536, 0x5db90eae
-537, 0xd2947d4c
-538, 0x8bd8856d
-539, 0xbc05a99b
-540, 0x1c2e0f5
-541, 0xb94d03a2
-542, 0xb8ed5ac1
-543, 0x199943d9
-544, 0x12482e5c
-545, 0x20aa7c9f
-546, 0x8733e45c
-547, 0x277b4f44
-548, 0x673d5a73
-549, 0xabc0aad9
-550, 0xbed6cd98
-551, 0x2943c24b
-552, 0x5237d6f9
-553, 0x1cb1a392
-554, 0xc7b69454
-555, 0x4f792707
-556, 0xa32ef400
-557, 0x7a5b6b72
-558, 0xa8683acc
-559, 0x418d0491
-560, 0x56e2470e
-561, 0xbe385495
-562, 0xe7944341
-563, 0x438abaab
-564, 0x82ad2c2
-565, 0x7afc306b
-566, 0xfcb88957
-567, 0x530414bd
-568, 0x2e3c7d41
-569, 0x633f7573
-570, 0xeffeefb2
-571, 0xf6de11f9
-572, 0x337710f2
-573, 0x88bf46dc
-574, 0x6fdaf5dc
-575, 0x34229d26
-576, 0x46b0aba0
-577, 0x78e40a29
-578, 0x7f9623cd
-579, 0x6cfe8779
-580, 0x1d4af99
-581, 0x78f97244
-582, 0xa198d714
-583, 0x9124883e
-584, 0x1cf88a12
-585, 0x69fe0966
-586, 0x78484a68
-587, 0xf9d8718b
-588, 0xcbf3ba5b
-589, 0xf67fb149
-590, 0xc95977c1
-591, 0x474f57f5
-592, 0x11bb9ec1
-593, 0xe28f21be
-594, 0x8ca6e21b
-595, 0x2609defc
-596, 0x989b6f6b
-597, 0x1c87383e
-598, 0xacd78f57
-599, 0x8c46cfcb
-600, 0xc37cce08
-601, 0x327d196a
-602, 0xf63c3572
-603, 0xc56780b5
-604, 0x9ac37d16
-605, 0xe692a39c
-606, 0x563938a3
-607, 0x1e80e32f
-608, 0x745652af
-609, 0xe425c9a8
-610, 0x11c71e82
-611, 0x9c721f6d
-612, 0xef89b973
-613, 0x494c7e80
-614, 0xadc29895
-615, 0xc7ee35ad
-616, 0x19beeb0c
-617, 0x9c25ae3f
-618, 0x27bf930f
-619, 0x223970a0
-620, 0x7cdb17ca
-621, 0xa49054f
-622, 0xf8321dcb
-623, 0x3f96a9eb
-624, 0x4468072a
-625, 0xfd7d727
-626, 0xee0af4f1
-627, 0xe6585512
-628, 0x56a6d8a1
-629, 0x40586642
-630, 0xb46bdaa0
-631, 0xe053a140
-632, 0x4de1953d
-633, 0xb6cbc718
-634, 0x2ed92c19
-635, 0x9da2840
-636, 0x6ab418b1
-637, 0x179f64cf
-638, 0x7c281c0
-639, 0x7015b62a
-640, 0x8d31e38e
-641, 0xa6de57ca
-642, 0xe509c4e1
-643, 0xa010162c
-644, 0xf71abd42
-645, 0x3d24ac8b
-646, 0xc2deb72f
-647, 0xd81570ba
-648, 0x17fc7d15
-649, 0xf17997b6
-650, 0xfa2ec5b5
-651, 0xbf7e189b
-652, 0xb3d9e761
-653, 0xe1194bd1
-654, 0x8d5280dd
-655, 0xdea2d148
-656, 0x6d85e66c
-657, 0x37f5fb07
-658, 0x65c1dd1
-659, 0xf52c04f8
-660, 0x4460d846
-661, 0x1729f55f
-662, 0xe03a699d
-663, 0x9f05ff9f
-664, 0x31abe986
-665, 0x64899f61
-666, 0x52fba7
-667, 0x2833ce74
-668, 0xa34d0e57
-669, 0x7203d492
-670, 0x1a63d91e
-671, 0x463781b7
-672, 0xf9842e7b
-673, 0x809276ad
-674, 0x88237b9d
-675, 0xaa648b06
-676, 0x9cf916bd
-677, 0x3b3068e4
-678, 0x20d6ae7d
-679, 0x7855dafd
-680, 0x9ebd14ed
-681, 0xc5934a1c
-682, 0xb3c421a1
-683, 0xa2b709a2
-684, 0x91fa8b34
-685, 0x9009a54
-686, 0xb2c4215f
-687, 0x7b294eb1
-688, 0x1802911e
-689, 0xa2067de5
-690, 0x5ebd85e9
-691, 0xc4f8e698
-692, 0xd143d368
-693, 0x2ca2b6fb
-694, 0xb5d27ebc
-695, 0x410146ca
-696, 0x9d6948fe
-697, 0xfafd0af5
-698, 0x290e9c5f
-699, 0x2ff06292
-700, 0x417903d5
-701, 0xc51af07c
-702, 0xd2bbaf6b
-703, 0xfa3720f1
-704, 0x4a6eb52d
-705, 0xed86ad3c
-706, 0x72a8676e
-707, 0xc3c2bbed
-708, 0x62b6a951
-709, 0xe08f9534
-710, 0xe2686ea5
-711, 0x3dbbf99b
-712, 0xfec5319f
-713, 0xef9c67eb
-714, 0x9d69d19b
-715, 0xc732ed2
-716, 0xc6e829bd
-717, 0xe712e882
-718, 0xd24594ca
-719, 0x102b8426
-720, 0xa5145730
-721, 0x62fecd71
-722, 0xe6439ca2
-723, 0x58819419
-724, 0xef722791
-725, 0x5ef6ab17
-726, 0x85ce3714
-727, 0xd4e18303
-728, 0xf91eb9c2
-729, 0x86bae692
-730, 0x6d81c21c
-731, 0xd9985982
-732, 0xfdd55f22
-733, 0x72ecd91a
-734, 0x4b1cee6
-735, 0xefa672ec
-736, 0x3f18114f
-737, 0xacae5e62
-738, 0x68369afd
-739, 0xff5e6612
-740, 0x3760af8c
-741, 0xd8c878bf
-742, 0x3945fe59
-743, 0x2cf7f99a
-744, 0x2cc59bb4
-745, 0xbba95cd6
-746, 0x6511688d
-747, 0xcf326178
-748, 0xf850cc68
-749, 0x4bd2540e
-750, 0xa02cf5e5
-751, 0x5546fcb5
-752, 0xe2b289fd
-753, 0x960c6ba
-754, 0x3a2c9d74
-755, 0x2def7a8f
-756, 0x54e57d43
-757, 0xf953c277
-758, 0xd9b414b1
-759, 0x19a25920
-760, 0xaf2691a1
-761, 0x81e88159
-762, 0x49a3eab
-763, 0x276a797d
-764, 0x98337885
-765, 0x37055fd0
-766, 0x6927effc
-767, 0xb6de7fc0
-768, 0x9e920f9a
-769, 0xd2dc9145
-770, 0xe2861109
-771, 0xe42e2c1e
-772, 0x836fe968
-773, 0x23452a15
-774, 0xd49f0e2b
-775, 0x2998f647
-776, 0x94f8c803
-777, 0xf8be479e
-778, 0xfd44079f
-779, 0x685ab9c1
-780, 0xea8eeab3
-781, 0x580ff5d8
-782, 0x88ad0666
-783, 0x19df5d86
-784, 0xe4862012
-785, 0x3ad25460
-786, 0x677449ce
-787, 0x1c7e0b9a
-788, 0x287a98d0
-789, 0xed39d094
-790, 0x40501707
-791, 0xb99073a4
-792, 0x31847bd4
-793, 0x91e5b7
-794, 0x46815e56
-795, 0xc823384c
-796, 0xdb6fb24
-797, 0xabe50dd8
-798, 0x2a33797b
-799, 0x4fb617ec
-800, 0x811a36df
-801, 0xb6b7a25f
-802, 0x8962cd0a
-803, 0xc40818fe
-804, 0x5dbe4e57
-805, 0x591f6c61
-806, 0x22aa4809
-807, 0xc0e4a72
-808, 0xa8a0e2e7
-809, 0xf91d553a
-810, 0x77674da7
-811, 0x196657d6
-812, 0x5ae38c0f
-813, 0x8bcf1ed2
-814, 0x9e0a2c8f
-815, 0xf94e5215
-816, 0x11299b2b
-817, 0xc499eca3
-818, 0x25e58d1b
-819, 0xdd722954
-820, 0x816f4c21
-821, 0x2504fd9b
-822, 0x722a597a
-823, 0x92f80aab
-824, 0xe2d7e54d
-825, 0xefb26dba
-826, 0x9ebf8863
-827, 0xd297ec21
-828, 0xa0ebfbb5
-829, 0xec609873
-830, 0xd079b3d1
-831, 0x920f722d
-832, 0xfd58146
-833, 0x5fbb5784
-834, 0x30187f5d
-835, 0x887f4ec6
-836, 0x6839a2ed
-837, 0x72bccd98
-838, 0x7565903e
-839, 0x8d3afaef
-840, 0xfb713a03
-841, 0x34216b35
-842, 0xbe0da7e9
-843, 0x4b11764e
-844, 0x6666922a
-845, 0x3f2dc90d
-846, 0xeca8fb8d
-847, 0x91579404
-848, 0x8d413df7
-849, 0x2a0f8307
-850, 0x39d5a495
-851, 0x79ba5e62
-852, 0xbb06fd0f
-853, 0x47ba4208
-854, 0x4a2efb9c
-855, 0xee3a07f0
-856, 0x291a73e0
-857, 0xe42a46c5
-858, 0x203455b2
-859, 0x40545253
-860, 0xa618bb0a
-861, 0xd4792a15
-862, 0xd6e62559
-863, 0x8149e2f0
-864, 0x5f6499a9
-865, 0xa63fc585
-866, 0xe33e1c1f
-867, 0x36ecb45b
-868, 0x267883ca
-869, 0x905d98fb
-870, 0xfac3512c
-871, 0x374d0a0e
-872, 0x9920f3e0
-873, 0xfb961c9f
-874, 0x70f2d752
-875, 0x69c44d12
-876, 0xcb6075d2
-877, 0xaf802ac8
-878, 0x2c4b792b
-879, 0xa2203217
-880, 0xc2c15619
-881, 0xb13af213
-882, 0x759b165c
-883, 0x411ecdf2
-884, 0x158e5fba
-885, 0x70874450
-886, 0x226a484f
-887, 0x87b95ecf
-888, 0x45cef22f
-889, 0xfaf186bd
-890, 0x3544972a
-891, 0xb4a2f73
-892, 0x5f5d10de
-893, 0xf3d05e29
-894, 0x7616ba85
-895, 0x4d2e198
-896, 0x1f240293
-897, 0x317c2286
-898, 0x3bd97e7b
-899, 0xd7e39d6f
-900, 0x142ee43c
-901, 0x688ada72
-902, 0xad8deac8
-903, 0xf7cc8d5e
-904, 0xa84600f5
-905, 0xda6b1b3
-906, 0x5bad09de
-907, 0x6f4276c7
-908, 0xa789933f
-909, 0xede4329a
-910, 0xa31f2df5
-911, 0x869c0c3c
-912, 0x6658f5b
-913, 0xdb451b7c
-914, 0x16ec0b18
-915, 0x2e35872c
-916, 0xf7bf3c44
-917, 0xda59c872
-918, 0x1ab63c0c
-919, 0x9a361a82
-920, 0xd2e1afcc
-921, 0x5c41ac55
-922, 0xd1d761db
-923, 0x3639bb85
-924, 0x7a418cfb
-925, 0xf0b06b8f
-926, 0xa2ef4d47
-927, 0x4fac4d1b
-928, 0x47e42283
-929, 0x6ee6a7df
-930, 0xfe786975
-931, 0x4475b665
-932, 0xd881e311
-933, 0x6b02224
-934, 0xcba19b84
-935, 0x4efa35f6
-936, 0x3873a72d
-937, 0x984d7964
-938, 0xe23cda62
-939, 0xea9949d2
-940, 0x243b83b1
-941, 0x48d1bcc4
-942, 0xe35b6a23
-943, 0x125288f1
-944, 0x72fdd401
-945, 0xa2af6873
-946, 0x7c211096
-947, 0xa00a13dd
-948, 0x7b4ce5d6
-949, 0x1e4be120
-950, 0xc771cc00
-951, 0x343ae31
-952, 0xe8e0be50
-953, 0xd9095a3f
-954, 0x616b7c17
-955, 0xa96e1580
-956, 0x60501426
-957, 0xeaac50b
-958, 0x130c33b5
-959, 0xba30925b
-960, 0xf942c440
-961, 0xc52e8e20
-962, 0x5f460318
-963, 0x94e1dadd
-964, 0xdfa4f20e
-965, 0xc9bbd26a
-966, 0x75322ecb
-967, 0x3dc3ff18
-968, 0xfa896826
-969, 0xe4ad213c
-970, 0x7a0f97c3
-971, 0xd7b7b08f
-972, 0x6ebcab4e
-973, 0x1a37d816
-974, 0x16299fee
-975, 0x89d94a3a
-976, 0x11c2f073
-977, 0x4ef27a32
-978, 0xaaf42781
-979, 0x9862c844
-980, 0xaa672e94
-981, 0xba4f2690
-982, 0x1f767d21
-983, 0x157e1a5e
-984, 0x5b6de343
-985, 0xc494501e
-986, 0xe97b507b
-987, 0x98cae4c8
-988, 0xc4a6b036
-989, 0x746f8686
-990, 0xe761c86
-991, 0xefdaaa15
-992, 0xb907b816
-993, 0xe9d05992
-994, 0xed2e1b0e
-995, 0xe129d3ee
-996, 0xb41bb95f
-997, 0xaec36181
-998, 0xdcdcf5f0
-999, 0xf175572a
diff --git a/numpy/random/tests/data/pcg32-testset-2.csv b/numpy/random/tests/data/pcg32-testset-2.csv
deleted file mode 100644
index 2d4c8aed1..000000000
--- a/numpy/random/tests/data/pcg32-testset-2.csv
+++ /dev/null
@@ -1,1001 +0,0 @@
-seed, 0x0
-0, 0xe4c14788
-1, 0x379c6516
-2, 0x5c4ab3bb
-3, 0x601d23e0
-4, 0x1c382b8c
-5, 0xd1faab16
-6, 0x67680a2d
-7, 0x92014a6e
-8, 0x628ae389
-9, 0xa794034d
-10, 0x5cc38cd9
-11, 0xfc913a3b
-12, 0x81c851dc
-13, 0x90c820e4
-14, 0x60dfa703
-15, 0xd613ae14
-16, 0x38ea1699
-17, 0x51f04d1b
-18, 0xc4ef01a1
-19, 0x321eec02
-20, 0x4c37a737
-21, 0x6bfd1aa8
-22, 0x71a28325
-23, 0x4656d6e9
-24, 0x17509653
-25, 0x830bd521
-26, 0x6d35e3aa
-27, 0x4ab85020
-28, 0x21c1da2c
-29, 0x6a6057a2
-30, 0xf3a90dc1
-31, 0xa1cbdcd9
-32, 0xf70b61bf
-33, 0x3b2b09a8
-34, 0xbc2ef54d
-35, 0xce07f38f
-36, 0xb51bc60b
-37, 0x729efb83
-38, 0x7e4a5f66
-39, 0xdd824ead
-40, 0x9be85945
-41, 0x57f8779c
-42, 0xdb449e87
-43, 0xc0be253f
-44, 0x18b4267e
-45, 0xff78821
-46, 0xb53e3425
-47, 0x4550b21b
-48, 0xefe89a4c
-49, 0x74c130b9
-50, 0x1656a3a0
-51, 0x194da2a6
-52, 0x1a6cdb1d
-53, 0x7c1fd58e
-54, 0x3162d1e9
-55, 0x3e2f2c7d
-56, 0xb0ab9b5c
-57, 0x79156d4d
-58, 0x97b85150
-59, 0x967a02ce
-60, 0x1e64548d
-61, 0x4196d24a
-62, 0xd047eef5
-63, 0x8451cc3c
-64, 0x7227eb94
-65, 0xb1191064
-66, 0x82e162d0
-67, 0xb473f07d
-68, 0x92ea0426
-69, 0xbf2a25fa
-70, 0x9935be52
-71, 0x28baec93
-72, 0xa29368b5
-73, 0xe3d6d97d
-74, 0x85ecf1d4
-75, 0x482e4bc8
-76, 0xe4f22219
-77, 0x7531047
-78, 0x3c41ef1f
-79, 0x19db5112
-80, 0xc1534caf
-81, 0x6c45710a
-82, 0xb323c369
-83, 0x2dac53c6
-84, 0xd5dc48b4
-85, 0x1dc6d7a1
-86, 0x3ae2bc10
-87, 0x6a7635e8
-88, 0xdeee7b7f
-89, 0xcb705cd3
-90, 0xba11e537
-91, 0xb64a4936
-92, 0xff4b245e
-93, 0x39cb1219
-94, 0x64833e10
-95, 0x76b0f975
-96, 0x333d7c7d
-97, 0x88ccfb17
-98, 0xad78dace
-99, 0xd82fb71
-100, 0x1595d411
-101, 0x47f9d57a
-102, 0xd4dad6cb
-103, 0x78bf16bd
-104, 0x71b053d2
-105, 0xa4bb076e
-106, 0xd7c57664
-107, 0x3fbcbf8f
-108, 0xc816befc
-109, 0x6df46890
-110, 0xd16f271f
-111, 0xeeeb1571
-112, 0x58222e89
-113, 0xa55e81d3
-114, 0xafbe7622
-115, 0x938475a8
-116, 0xd8740af2
-117, 0xf937dbd7
-118, 0x7d3940fa
-119, 0x694c55f2
-120, 0x2261fb68
-121, 0x6ce39e94
-122, 0xab43634
-123, 0xd92ff7c4
-124, 0xe8db22d
-125, 0x52e250b1
-126, 0xaf0f7029
-127, 0xc23dd3a
-128, 0xd66dc2b9
-129, 0xea7f01f3
-130, 0x4df54b3f
-131, 0xf1eff09c
-132, 0x2813663e
-133, 0x21ae8115
-134, 0xb00d790d
-135, 0x11e6adbb
-136, 0x61005f4c
-137, 0x3de17bf0
-138, 0x7b2050b9
-139, 0xe20dd275
-140, 0xafa0bdcc
-141, 0x9c6d4c6c
-142, 0xe938606
-143, 0x8eecdd8f
-144, 0xea9a90a9
-145, 0x99cbb123
-146, 0x16fccad1
-147, 0x7e81fdd9
-148, 0x116e6abd
-149, 0xdeb9ff4e
-150, 0xc589f525
-151, 0x57d701a9
-152, 0xcf05e950
-153, 0x533a2839
-154, 0x12d592e7
-155, 0xae61f43f
-156, 0x419ae221
-157, 0x81126e0a
-158, 0xc3988c97
-159, 0xb3262eaa
-160, 0x3baddf9e
-161, 0xf19d8a16
-162, 0x2a8b130f
-163, 0xe4c9ccea
-164, 0xf5ae2ea
-165, 0x75aaa98d
-166, 0xdd45ce49
-167, 0x98e0d4f6
-168, 0xb1ec10a1
-169, 0xc9592952
-170, 0x23bb1f45
-171, 0xd0827b45
-172, 0x7a79b800
-173, 0x9d1b8348
-174, 0xe2958863
-175, 0x5143e17e
-176, 0x44110af9
-177, 0x49d76858
-178, 0xdba4688e
-179, 0x4e4d61dd
-180, 0x729b81cc
-181, 0xf3576e03
-182, 0x9b028e9d
-183, 0x68d8d869
-184, 0xda15e018
-185, 0x5384abb2
-186, 0x1027ed5e
-187, 0xaf5401f1
-188, 0x31411375
-189, 0xc75d87be
-190, 0xad73f5fd
-191, 0xadb3add7
-192, 0x4d5452ee
-193, 0xdef42029
-194, 0x89d58a78
-195, 0x464d6b4a
-196, 0xd01f533a
-197, 0xb9533dd4
-198, 0x55c5d023
-199, 0x3dcf8fef
-200, 0x198395ca
-201, 0x7cdca51c
-202, 0x6f4074f
-203, 0xb9f79995
-204, 0xbbe3d9a5
-205, 0x520d417e
-206, 0x9a8df0bd
-207, 0xe390f486
-208, 0x5b578b3f
-209, 0xb4cdf767
-210, 0x12d45034
-211, 0xe661e293
-212, 0x70cd3e91
-213, 0xdbc7f190
-214, 0x49829849
-215, 0x12017fbe
-216, 0x1e35bf48
-217, 0x1effc3c7
-218, 0xe1f574cb
-219, 0xf613ab7d
-220, 0xd09d16fa
-221, 0xa58bcf5a
-222, 0xac39afdc
-223, 0xd611d1ab
-224, 0x36edd3b2
-225, 0xd9ea5d98
-226, 0xf6f2fce4
-227, 0x42cb31ce
-228, 0xdd1f6530
-229, 0x3e43a7d0
-230, 0x175ec7fc
-231, 0x8077af4b
-232, 0x37cbcc22
-233, 0x26a89f
-234, 0x998c930e
-235, 0xb84e5f21
-236, 0x83817130
-237, 0x2ad05d66
-238, 0x48f3b861
-239, 0xd69f626
-240, 0x1d09f12
-241, 0xf207e7f0
-242, 0xcc709acc
-243, 0x1b2881d7
-244, 0x7e18cc6c
-245, 0xbfd9589c
-246, 0xce0d301e
-247, 0xc8668b4b
-248, 0x584482bd
-249, 0x722e14ae
-250, 0xd79dfcff
-251, 0xcc7e9c21
-252, 0xd081f540
-253, 0x3b49f7fa
-254, 0xf23efb2a
-255, 0xfd7fe8f8
-256, 0x9abcbf25
-257, 0x5b713674
-258, 0x1300e351
-259, 0xe884f0ad
-260, 0x3c290461
-261, 0x4f64c1a1
-262, 0x17c55223
-263, 0xd5953a5f
-264, 0xd85e042e
-265, 0x75dfc597
-266, 0x379edfb
-267, 0x75ebddc9
-268, 0xc19b98e1
-269, 0x1dd1b751
-270, 0xc5760a60
-271, 0x5f6e2f17
-272, 0x29e8610e
-273, 0xb2edd7db
-274, 0x9233eeca
-275, 0xbc02b187
-276, 0xc997bb5b
-277, 0x88ad3a98
-278, 0x3d1167ad
-279, 0xcea54c9c
-280, 0x7ea493eb
-281, 0x586e3aa8
-282, 0xe2e027c7
-283, 0xae50ef9e
-284, 0xd32e0c38
-285, 0xeba0edf6
-286, 0x980ad22a
-287, 0x3b14e644
-288, 0xd7bfbff8
-289, 0xe0af1647
-290, 0x292d72dd
-291, 0xb8c421bb
-292, 0x114d690e
-293, 0x85a86bd
-294, 0x39f2b5e2
-295, 0x7c9c6b43
-296, 0xca387767
-297, 0x84f24ecf
-298, 0x2aec5804
-299, 0x27d0f2
-300, 0xcd7bb6a9
-301, 0xe925969f
-302, 0xc6454099
-303, 0xf7435a9d
-304, 0xf7bc998f
-305, 0xfa81f361
-306, 0xcba07d00
-307, 0x3e8a8a14
-308, 0xf0e7f785
-309, 0x25aecff
-310, 0xe1a90226
-311, 0x4af1339d
-312, 0x983f4fb9
-313, 0xbaec847f
-314, 0x4e504dbb
-315, 0xe7d0be86
-316, 0x73cb80ef
-317, 0x336db698
-318, 0x8bf7de05
-319, 0x36e4e6ba
-320, 0x47a8239b
-321, 0x2a98e1d0
-322, 0x64a6c087
-323, 0x4a8591cb
-324, 0x642d5d67
-325, 0x9f4b84b2
-326, 0x6bdf1176
-327, 0x7e2b1639
-328, 0xc90453f5
-329, 0xe72d0b96
-330, 0x5f0e1d0c
-331, 0x156af798
-332, 0x6124d8e8
-333, 0xaa2f2ad7
-334, 0x145b30b7
-335, 0xd6582106
-336, 0x203abbad
-337, 0x929d8d43
-338, 0x14d5b6dc
-339, 0xef0f4eb2
-340, 0x8ff54463
-341, 0x588113a
-342, 0x1bc43ba6
-343, 0x44f44097
-344, 0xb84cfdc6
-345, 0x3ee638af
-346, 0xdd169321
-347, 0xaaac5f56
-348, 0xbb022bc2
-349, 0xf9ef8bde
-350, 0x2829b2fb
-351, 0x563368fa
-352, 0x82ce66ae
-353, 0x6d820e38
-354, 0xb87a080e
-355, 0x756469af
-356, 0x78086990
-357, 0xa220e762
-358, 0x14ba6bdb
-359, 0xfa775c1b
-360, 0x65fa7396
-361, 0xbae24370
-362, 0x8e42ddb8
-363, 0x1f46b8ac
-364, 0x3c9236c5
-365, 0xd3a2184c
-366, 0x308ba74
-367, 0x5638eb84
-368, 0x64076fe6
-369, 0x37fe334f
-370, 0x8de24732
-371, 0xf0d0b02b
-372, 0x18492b71
-373, 0x848f38ac
-374, 0x9b46dc75
-375, 0xf5d3c06a
-376, 0x203afe47
-377, 0x19857724
-378, 0x38033528
-379, 0xf7fa640c
-380, 0xf1cb86e8
-381, 0x1fcd5b99
-382, 0xb07f1023
-383, 0x3bb9ab75
-384, 0x57f54e78
-385, 0xf5b51d4b
-386, 0xe94eba44
-387, 0xa5a39292
-388, 0x50803af
-389, 0x34ea9cc5
-390, 0xabf621ca
-391, 0xb275f802
-392, 0xf46dffd6
-393, 0xd33e27d1
-394, 0xca9a56e
-395, 0x6eda85a4
-396, 0x639b78ba
-397, 0x799d1980
-398, 0xf3c09bf1
-399, 0x6d4cdbe
-400, 0x112dae8d
-401, 0xd97414b1
-402, 0x9499df3d
-403, 0xa58ece6c
-404, 0xe56bf91b
-405, 0x3bdbfd9
-406, 0x91aae1fd
-407, 0xec1fce54
-408, 0x60e0eced
-409, 0x278d5b22
-410, 0xdee29da2
-411, 0xf1f55d27
-412, 0xd532ab83
-413, 0xb0fe9589
-414, 0x88fcc255
-415, 0xf524359b
-416, 0x7270a00b
-417, 0x42489eaf
-418, 0xc020d6bb
-419, 0xf9ed0f78
-420, 0x4bc5cdec
-421, 0x55061393
-422, 0x6b84a5a4
-423, 0x826c0471
-424, 0x9e69e30d
-425, 0x9dfd9b15
-426, 0xf4014c40
-427, 0xcd04ef4d
-428, 0x7376c02c
-429, 0xb15a9e3c
-430, 0xf76c1fa9
-431, 0xcd51bdd8
-432, 0x99f2859e
-433, 0xb62c6a4d
-434, 0x52239d8b
-435, 0x27fa2869
-436, 0x6dba918c
-437, 0x9891e444
-438, 0x71e29f5
-439, 0xa9cd3ac9
-440, 0xf6ec3b80
-441, 0x8c8d3226
-442, 0x7c528725
-443, 0xd543932b
-444, 0xf76b3e02
-445, 0xeccaf183
-446, 0x8f757854
-447, 0x785edb62
-448, 0x54397da0
-449, 0xe1fe0557
-450, 0x7a79d418
-451, 0xd2740507
-452, 0xc3561bc7
-453, 0xef7c3f18
-454, 0xecf8effe
-455, 0xc7a073ad
-456, 0xeb5ea9fd
-457, 0x33dade18
-458, 0x89d0e41c
-459, 0x7720d298
-460, 0xe912f029
-461, 0x7794462
-462, 0xa436dcf6
-463, 0x55cbb318
-464, 0x7b4a78e0
-465, 0xa8ce0afb
-466, 0x7e18bb28
-467, 0x92c4f8f6
-468, 0x6828052c
-469, 0xbf619f8
-470, 0x272d1d15
-471, 0xb34e2e52
-472, 0x52158f7f
-473, 0x682fb062
-474, 0x52e80435
-475, 0x787e0fb3
-476, 0xe331da39
-477, 0xfad42e58
-478, 0x1bdb3f90
-479, 0xe313ab2
-480, 0xe61af9bb
-481, 0x46f03903
-482, 0x926b3d33
-483, 0x2b23ce3b
-484, 0xed04d4af
-485, 0x34c49faf
-486, 0x142f503c
-487, 0x47cf6a21
-488, 0x5352250c
-489, 0xf5942210
-490, 0xca5950ae
-491, 0xc5302422
-492, 0x41a5e9b1
-493, 0x30076390
-494, 0x8951d0e4
-495, 0xebe74e22
-496, 0xfcb7dbf8
-497, 0xd55076e7
-498, 0x88a1165b
-499, 0x1a89b5a3
-500, 0xda2c3e2e
-501, 0xdc1d606d
-502, 0xfda0315c
-503, 0x5f5610dd
-504, 0x3eba316c
-505, 0x72cae07b
-506, 0x5336095
-507, 0x6a110322
-508, 0x46cb153b
-509, 0xa2b11116
-510, 0xe2543988
-511, 0x51f53bae
-512, 0x3b10466d
-513, 0x189ddd56
-514, 0x1fd355b6
-515, 0x1230e8d3
-516, 0x2050d313
-517, 0x2fbb5c16
-518, 0x64b03f4f
-519, 0xbd6cdc1a
-520, 0x9d423316
-521, 0xc71a702f
-522, 0xf2254f39
-523, 0xd953728b
-524, 0xef3c8bb5
-525, 0x685a2fab
-526, 0xcea73dff
-527, 0x4a7fa029
-528, 0xa27e8058
-529, 0x561a1413
-530, 0x570fc5bc
-531, 0x917e93ee
-532, 0x15fdbb15
-533, 0xabee295e
-534, 0xc40f5307
-535, 0xba18b087
-536, 0x6ea6e339
-537, 0x7e282248
-538, 0x875062c2
-539, 0xd1520c30
-540, 0xb4cef1a5
-541, 0x55812dd1
-542, 0x9c67743c
-543, 0x22fd5992
-544, 0x1dacbfa
-545, 0x5b35eab1
-546, 0xfa8c9316
-547, 0x490bc71c
-548, 0xe5129bfb
-549, 0xe7acb79f
-550, 0x87667765
-551, 0x945be067
-552, 0x8acf5c32
-553, 0x466e0ee
-554, 0x8fa89be0
-555, 0x4eb4afcc
-556, 0x3302055b
-557, 0x8f2e3ab9
-558, 0xc5bc175e
-559, 0x903a3e85
-560, 0x4055dd04
-561, 0x37873bac
-562, 0x2965a951
-563, 0x2206c56a
-564, 0xf34dc2db
-565, 0x34e43ba2
-566, 0xb61caa44
-567, 0xfd3eb260
-568, 0x9dcdc817
-569, 0x7019df83
-570, 0x6fcd9bea
-571, 0x270cba0a
-572, 0xd6cc3241
-573, 0x6345c906
-574, 0xd213fb94
-575, 0x6195e5b5
-576, 0x804abab7
-577, 0xb4cace45
-578, 0xded19bbc
-579, 0x617db00c
-580, 0xafb933d6
-581, 0x8192cae8
-582, 0x45ffd8af
-583, 0x13ae0868
-584, 0x840f4541
-585, 0x12cd1a05
-586, 0xbb5b7d6d
-587, 0x3907ab3
-588, 0xd77a1582
-589, 0x4e741292
-590, 0x28c60865
-591, 0xbaad11e2
-592, 0xa9d3e364
-593, 0x88a197cb
-594, 0xe90f021f
-595, 0x2056017a
-596, 0xeb0a2fd9
-597, 0x1d3435aa
-598, 0xdaa0b802
-599, 0x8121bf09
-600, 0x95a88f55
-601, 0xa8b9c257
-602, 0xb0ab4914
-603, 0xf360b741
-604, 0x5563d4ab
-605, 0xad33cf0e
-606, 0x397d315a
-607, 0x6893767f
-608, 0x79dd5b31
-609, 0xa9ea6777
-610, 0xcf48c06
-611, 0xb4cceafc
-612, 0xf53cab50
-613, 0x72426c8
-614, 0xd128aa5a
-615, 0x511eec88
-616, 0x668ab20a
-617, 0xb9b53dbe
-618, 0x3b03a0fb
-619, 0x8f416a98
-620, 0xaa15b7f6
-621, 0xc7767aba
-622, 0xa64d3342
-623, 0x42cf1388
-624, 0xfc3ee7c0
-625, 0x892a2902
-626, 0xdb054bf6
-627, 0x4973223f
-628, 0xb9f74682
-629, 0x72f2ece
-630, 0xddf94382
-631, 0x67581d86
-632, 0x9cb9cd6f
-633, 0xed74731a
-634, 0xcca05451
-635, 0x3b21fdc0
-636, 0x9e18e52b
-637, 0xa40bb287
-638, 0x8bb05e07
-639, 0xa33555fe
-640, 0x4c819ed
-641, 0x5373903e
-642, 0x611403c2
-643, 0x133e25fb
-644, 0x9c7a44e4
-645, 0x67197b8d
-646, 0xfa910436
-647, 0xa86a825d
-648, 0xfc9b24c1
-649, 0x464a718e
-650, 0x7421bc26
-651, 0x3c3186b7
-652, 0xf7304619
-653, 0x7ac7be81
-654, 0xae6adcc4
-655, 0xca96bf8c
-656, 0x49711d50
-657, 0x74c51f0
-658, 0x275804c0
-659, 0x228098c5
-660, 0x73a31b94
-661, 0x7f01db79
-662, 0xb36209c8
-663, 0x6ccf8677
-664, 0x70dbcce0
-665, 0xa533d8cd
-666, 0xd0b0f097
-667, 0xd9a3b784
-668, 0x80a929fc
-669, 0x9708f29a
-670, 0x95e1e56f
-671, 0xd07a0b45
-672, 0x566acdb6
-673, 0x92663054
-674, 0x3667dc9a
-675, 0x80f850ff
-676, 0x549dd640
-677, 0xc3ff18ca
-678, 0x8c70d392
-679, 0xf5547e3b
-680, 0x8dbee1d7
-681, 0x51fe33b8
-682, 0xb1ea480b
-683, 0x6646f6d0
-684, 0x4a8e7de9
-685, 0xcb053e32
-686, 0x6311aee8
-687, 0xcc2a411b
-688, 0x5330e60b
-689, 0x4680e825
-690, 0x96bdd8a2
-691, 0x8cf4268a
-692, 0x8445c833
-693, 0xc237eef1
-694, 0x459670e8
-695, 0xedf26624
-696, 0x5713340f
-697, 0x5a3e87a3
-698, 0xa24a7c2d
-699, 0xfa9fdceb
-700, 0x746fd14e
-701, 0xc6aef3e5
-702, 0x3d957e9b
-703, 0xc1926f7a
-704, 0xee717768
-705, 0x101fe323
-706, 0xec0d63ab
-707, 0x8b8e6f42
-708, 0x8c3d2286
-709, 0xb573dd68
-710, 0x53b68ec0
-711, 0x696525cf
-712, 0xdab65d8e
-713, 0xd2c6ed42
-714, 0xa1fc10f6
-715, 0x1554666
-716, 0x6ed42947
-717, 0x87f7e62
-718, 0xaf34733b
-719, 0xc55baa8b
-720, 0xcbff66f
-721, 0x2516c228
-722, 0xec6980fb
-723, 0x4f53d66c
-724, 0x1be17a32
-725, 0xdcfb31df
-726, 0x4b17d04f
-727, 0x81e1f54b
-728, 0x749eae52
-729, 0x3811c4d5
-730, 0x5d11e6a1
-731, 0x535d5d6c
-732, 0xbb74cd20
-733, 0xd1b18b71
-734, 0xfbf7221a
-735, 0x817c4279
-736, 0xcef30b85
-737, 0x41dee06c
-738, 0x9d340a3a
-739, 0x691f0449
-740, 0x363a515d
-741, 0x73a1af6c
-742, 0x25718271
-743, 0xb4a52d50
-744, 0x1e392f40
-745, 0x3c811345
-746, 0xc9aa8565
-747, 0x357c24e0
-748, 0x19ad7230
-749, 0xed250e20
-750, 0x4acc4824
-751, 0x825d53a
-752, 0xcf2f515f
-753, 0xb7973ff4
-754, 0xb03ce53f
-755, 0x1afad500
-756, 0x39f64ee8
-757, 0x60bea483
-758, 0xedf16817
-759, 0x88beff73
-760, 0x4909868
-761, 0x879a96da
-762, 0x52d4ac6b
-763, 0x46fabe65
-764, 0x88fa5751
-765, 0x71df4521
-766, 0xfc6eb286
-767, 0xf83e78ad
-768, 0x885e5aca
-769, 0x77e63e4a
-770, 0x2bdf5c02
-771, 0x2528323c
-772, 0x5b5d1ce9
-773, 0xf795be8c
-774, 0x5e113b2b
-775, 0xa993c7aa
-776, 0xe5f8560a
-777, 0x77e1e8d
-778, 0x5e9db88a
-779, 0xdac4e96b
-780, 0x9126b945
-781, 0x15bf293a
-782, 0x1dc9a8f4
-783, 0x909b48b1
-784, 0xb50ce29e
-785, 0x21671c87
-786, 0xcda80dec
-787, 0xf5aff1a9
-788, 0xd70cdb2e
-789, 0xd293139a
-790, 0xcbf4f51d
-791, 0xb23c6d7a
-792, 0x1a06aa33
-793, 0x21880210
-794, 0x92679678
-795, 0x8d5bb26b
-796, 0x23304100
-797, 0x8f5d1df4
-798, 0x143b39ff
-799, 0x29e97d16
-800, 0xbfad952f
-801, 0x257ca1d8
-802, 0x32ad2f8f
-803, 0x84d320c3
-804, 0xcc4c59a
-805, 0xbb5ae046
-806, 0x3d5fcf1d
-807, 0xa0130b0
-808, 0xad86e9de
-809, 0x1e422521
-810, 0x6b56a617
-811, 0xbe64d9fc
-812, 0xfff31ed0
-813, 0xd1ad616e
-814, 0x13486a20
-815, 0x1754613b
-816, 0x52c7b9da
-817, 0xc05d75aa
-818, 0xd719cd98
-819, 0x61890574
-820, 0xc4711a8b
-821, 0x9afd5635
-822, 0x4dabed21
-823, 0x94f173
-824, 0xb8b6e708
-825, 0x1d590111
-826, 0x60315dfd
-827, 0x7fb8ae79
-828, 0xc69f4f2b
-829, 0xcaf1c898
-830, 0x861a0c8b
-831, 0x6ed14eaa
-832, 0xc77da58
-833, 0x8fd4f29a
-834, 0xa38187fb
-835, 0x6ed1ee88
-836, 0xf1a9f55a
-837, 0x74368cc8
-838, 0xf327e944
-839, 0x97a578af
-840, 0x8a5345e5
-841, 0x63ee0a30
-842, 0xa7e4919b
-843, 0x51e26930
-844, 0x38dbe017
-845, 0xedace3a9
-846, 0x9cda2ad4
-847, 0x96b1119
-848, 0xff56282a
-849, 0x71773edf
-850, 0xe41fb69c
-851, 0xe7bce539
-852, 0x221ffeed
-853, 0x35d3f67f
-854, 0x7e089168
-855, 0x6fd47823
-856, 0x43bfb28d
-857, 0x9ce49e62
-858, 0xde32120
-859, 0x6eacfe4e
-860, 0x116c6128
-861, 0x5f975284
-862, 0xc547361c
-863, 0xf48e8251
-864, 0x2ac8a3bd
-865, 0x9a0fce5b
-866, 0x1764e3d9
-867, 0xa31e6954
-868, 0xb9dca055
-869, 0x1cd35c79
-870, 0x1b502882
-871, 0xf973ab10
-872, 0x8b585146
-873, 0x841fd3f8
-874, 0x4999200f
-875, 0x7ad10c4b
-876, 0xcf1695bd
-877, 0x26c58bc3
-878, 0xdc1f8310
-879, 0x546e1e86
-880, 0x2e39fec8
-881, 0x8c65e2ed
-882, 0x6469bac
-883, 0xbc4af1ff
-884, 0xa1669010
-885, 0x41dabd80
-886, 0x5797e218
-887, 0x9bed24c1
-888, 0xa7552347
-889, 0x4e214099
-890, 0x34d4f986
-891, 0x316cc527
-892, 0xde30c21c
-893, 0x4f273c1e
-894, 0xc3dd9324
-895, 0xe61fda1c
-896, 0x1d0f8076
-897, 0x5570867e
-898, 0x289d6062
-899, 0x465b8b26
-900, 0xb72307de
-901, 0xe78c8647
-902, 0xfee9723e
-903, 0xa1534c9b
-904, 0x4d652645
-905, 0xe623b6c2
-906, 0x454cfc8
-907, 0xc5a7fcaf
-908, 0x1de804d9
-909, 0xa2501de7
-910, 0xe036c091
-911, 0xa4a55d1d
-912, 0x50409892
-913, 0x58fd2731
-914, 0xb6fd3618
-915, 0xa0180bd2
-916, 0xd9bb2fe8
-917, 0x7c8e7a2c
-918, 0xd90906fc
-919, 0xf8721260
-920, 0x451b372d
-921, 0xeeb1c70
-922, 0xc1a18778
-923, 0xd466244a
-924, 0x88e4b84a
-925, 0x4fc3af63
-926, 0xcf4387e4
-927, 0xb8872734
-928, 0x276eadef
-929, 0xd2c164a1
-930, 0xd3c812d9
-931, 0x5a94f176
-932, 0xfba6f632
-933, 0xf7aeba97
-934, 0x9207585f
-935, 0x70a41d67
-936, 0xa0b70910
-937, 0xd579fc6b
-938, 0xf06a8fca
-939, 0x471fd406
-940, 0xb15a0491
-941, 0x2f340f7a
-942, 0x3df02de3
-943, 0x6022f8d6
-944, 0xa15b11c2
-945, 0x45715dd6
-946, 0xf293d85e
-947, 0x7a2100d
-948, 0x7dff786e
-949, 0x52c6a183
-950, 0x5fbce2db
-951, 0xbc29ec65
-952, 0x3dd14b27
-953, 0x1bedecd1
-954, 0xbfcba31c
-955, 0xb911a26d
-956, 0x6b6de680
-957, 0x36e8769
-958, 0x908de4a0
-959, 0xe1abee1f
-960, 0x83acd7f8
-961, 0x5008c1eb
-962, 0xd8bc7a2b
-963, 0x6f639c56
-964, 0xe1f2634b
-965, 0x267222ec
-966, 0x48fa416c
-967, 0xfa01e3cb
-968, 0x2d28a700
-969, 0x58dcdc97
-970, 0x685ac2e7
-971, 0x9318840b
-972, 0x99247a55
-973, 0x8d749b83
-974, 0x403f8415
-975, 0x373eb9c6
-976, 0xb840b6a2
-977, 0x9bb7bfc4
-978, 0xd5800634
-979, 0x3ef4a02d
-980, 0x2ffa791f
-981, 0x8a671150
-982, 0x40fdfc5e
-983, 0xfa4bd35e
-984, 0xf4ca1642
-985, 0x17fb231a
-986, 0x42a3e57c
-987, 0x58cf119d
-988, 0x32f19c67
-989, 0xf3e2e153
-990, 0x66fce6fb
-991, 0x9d61059b
-992, 0x1628eafb
-993, 0x9a6cf683
-994, 0x5ff5df3a
-995, 0x206fb3c9
-996, 0x1914913c
-997, 0x58c002ad
-998, 0xd099145f
-999, 0x155aab4b
diff --git a/numpy/random/tests/data/pcg64-testset-1.csv b/numpy/random/tests/data/pcg64-testset-1.csv
deleted file mode 100644
index da6d77d40..000000000
--- a/numpy/random/tests/data/pcg64-testset-1.csv
+++ /dev/null
@@ -1,1001 +0,0 @@
-seed, 0xdeadbeaf
-0, 0xb174ddf3fe597da6
-1, 0xfc217240c1e61e6f
-2, 0x20279da26fec9cbf
-3, 0xa5f4ee34651f4e1e
-4, 0xb254d7901c68b9db
-5, 0x6bf2a64e4052c36f
-6, 0xbec4c7418c0f61b6
-7, 0xb03e595a4ef2b2bd
-8, 0xc8e051957ccb74c6
-9, 0xf5082df7473c6f62
-10, 0xb72aa3dc22752a38
-11, 0x7a941561514bd680
-12, 0x90a95f42834f347b
-13, 0x88e17b9d59def797
-14, 0x18f19c86bfe60368
-15, 0x667f89277be8d1d8
-16, 0x63305475e7aeff27
-17, 0xd7e4d5c09fb0fb4c
-18, 0x7dd6deab03a8c26a
-19, 0x42bbcb746e2d4b26
-20, 0xe91f2ac4fa90689c
-21, 0x2f83458da0af3125
-22, 0x49a43537a00fae89
-23, 0xef02111d1ebc16eb
-24, 0x32b3b3019875f3e7
-25, 0x89eb15c48cd02774
-26, 0xa9f1b37865752731
-27, 0xe0eff9dadc47fb3
-28, 0xae859b1c54cc90c2
-29, 0x7b7c5e04d5015dec
-30, 0x38faeff5ce3266ff
-31, 0xd2ddd0d19fbc24ee
-32, 0xe0d4f692829a31a9
-33, 0x30a6aa3f408e71c2
-34, 0x298362be21de6d44
-35, 0xb7efab759e691149
-36, 0x2ae1f84bba093d4c
-37, 0xf6ab55f78f8b9258
-38, 0x2275d0af583cec95
-39, 0x18cfe066b183ac3c
-40, 0xcc0a546d54064cf5
-41, 0x5de027ea3c25c225
-42, 0xdaf31ef489fe71e1
-43, 0xa7a2b1a72a4360e7
-44, 0x678a55d7a0506791
-45, 0x36facd8799ad2b78
-46, 0x32fec94506dca70e
-47, 0x34e890d8539871f8
-48, 0xec48b5362b0d7818
-49, 0xe2e58921cf8228d3
-50, 0xd163588ec22730a4
-51, 0x17e2322b6be47d25
-52, 0xe1544989a0c6d24f
-53, 0xa3a10fb279cdc347
-54, 0xad4ee318a5853900
-55, 0xc96a185feef4a85d
-56, 0x82ec5b3aed6636fb
-57, 0x2aac2ef8f25426d7
-58, 0xa81e3114165e0d08
-59, 0xc1d8128f83969da5
-60, 0x157505508eaf50f1
-61, 0x77c175067c9c199c
-62, 0x973052089bd7af0
-63, 0x3cd70041e32c1921
-64, 0x7783719f13a254a0
-65, 0x2216485ff502d9ff
-66, 0x7dae695d2c7f3b79
-67, 0x809ce710156fea36
-68, 0xb90ac31262460e4e
-69, 0xc1afe8019306e7d7
-70, 0x6c57638edba4ca0a
-71, 0xbe6133f6ab1e9aeb
-72, 0x8f5699ff0bcf341d
-73, 0x69d0218df036bcbc
-74, 0xf0976fd79735d47d
-75, 0x82b36a795e5cc74b
-76, 0x263c30766b985686
-77, 0xf7426f94511d5ba0
-78, 0x8b04f9573050ed9e
-79, 0x7280d4ec202e8359
-80, 0xa8235fbd1324f172
-81, 0x6dbd5d500a809a8c
-82, 0x26c53c69292bca1d
-83, 0xe348f657b20305ec
-84, 0x562f0e2fbb375421
-85, 0xdf2be07bebfbe447
-86, 0x4275044640683760
-87, 0xad5d68bfe4ab4858
-88, 0x3c0e57df5b3306f0
-89, 0xc9d87622ac847565
-90, 0x83d04fd9e102c311
-91, 0x71996b9c65aaf5c0
-92, 0xe3df32742d6fc446
-93, 0x58d3a6573a39d0cb
-94, 0x74dfa090e96d289d
-95, 0x7856f45e5416c1ea
-96, 0x80a18e88b3e4dff8
-97, 0x60565bbcb04f56ac
-98, 0x9f4cf5ec45fae3a6
-99, 0x885d2909fe34e3f0
-100, 0x7a1db9118f60dee0
-101, 0xc4c17dc810746c7e
-102, 0x8b954b14effe83b1
-103, 0x4f89fb0940999c86
-104, 0xc62e634bceca1c97
-105, 0x7e06e87dffd1619f
-106, 0xd1ccbce841371671
-107, 0xe7f99698c66df1b3
-108, 0x5302c2f0e4e1f4e0
-109, 0xa57d11d3d7ee652e
-110, 0x8abe0ed0e5508407
-111, 0x6780588af9f6c2ff
-112, 0x8603a9fc73b6a4cd
-113, 0x169c13a0b7a166b9
-114, 0x868969fb53578598
-115, 0x6089e0eacbe69039
-116, 0xf82482d424397dc2
-117, 0x11475d20896fc890
-118, 0x7983933df29e2aa0
-119, 0x4889c4780cd8e9cc
-120, 0x53ebb258f3ea266b
-121, 0x121896059b256fd1
-122, 0x2f9934516b2f8090
-123, 0xbabb9fa1d1efa60c
-124, 0xfb0b1370ea044797
-125, 0x782ab293b597bc8e
-126, 0x297fc0b3977271f5
-127, 0xa573e4d0674d02fc
-128, 0xc7e8ddb6efe8a2db
-129, 0xaae8a024e62f6e32
-130, 0x3217a47698c9e439
-131, 0xd7015db847a3de0b
-132, 0xbc0b4368776e10a7
-133, 0x69d9ef0178679bfb
-134, 0x28fd8f0936b66fab
-135, 0x45b1c4d4aa9b5aca
-136, 0x28feade39cd3ac00
-137, 0xa7e6515c534520f1
-138, 0x735703b5f4bfd54e
-139, 0x798271ae0c91b8d8
-140, 0xf858458f9efa8d2
-141, 0x6a41f5845422a9e
-142, 0x7fb0bba5f097aab0
-143, 0xbfaea58fe090e745
-144, 0x84770504bfb15b35
-145, 0x67ae11aa368049b8
-146, 0x846c5e493ee15e4a
-147, 0xbbcf3baf029f056c
-148, 0xd30c23bde142a356
-149, 0x32cd403edb746a8d
-150, 0x40161ab00c636730
-151, 0x3a882c3c60d3e19a
-152, 0xca8faab24d826529
-153, 0x241a687288551d04
-154, 0xbbc607fb9b48ac00
-155, 0xa844329d0c2d475a
-156, 0x8fa4aa1d7296b9e4
-157, 0x82c7dc1f588ce2fc
-158, 0xcbdaa663041e078c
-159, 0xec108d219b2b147a
-160, 0xcab01864270b334
-161, 0x6d3d08545041621b
-162, 0x2aae054b8e5648f
-163, 0x1bf5a72fa70e7eab
-164, 0x2dddb2050af45a3a
-165, 0x2b910b7078021a75
-166, 0xf7160201ede45f4e
-167, 0xfaf75ae996f079bb
-168, 0x407984a9451e659c
-169, 0xbdf9c0a9ea078ac0
-170, 0x1e7717b8345acbb6
-171, 0x25cc2df4c0c8dc4a
-172, 0xfda1715b573850db
-173, 0x50e5cedad99e2651
-174, 0x9a67673ed73cfc0
-175, 0x802ec4fc9e946805
-176, 0x677cd320e641999f
-177, 0xbfeb1b6053fe4f78
-178, 0x220cfc90bd31541
-179, 0xe4fdfae10ae6c86f
-180, 0x76c568fd869af80d
-181, 0xd17dc57109200bb1
-182, 0xeb96ba01c95382be
-183, 0x6a9c7ebea5b5f7ac
-184, 0xc1680450532fb8cd
-185, 0x26b0829f68888094
-186, 0x98335aa1612d7c70
-187, 0xad8662125bf32ae3
-188, 0x15f18a9025ae26e8
-189, 0x5d065dba0d17c9fc
-190, 0xf68e1d59f10ff109
-191, 0xcfbd97901a79f8b0
-192, 0x3e72a9fd1d95f143
-193, 0xe7ee82c1bb740dfd
-194, 0x3a0f4ae5db22527b
-195, 0xf4d025080ed4ea92
-196, 0x6924a99549b4657
-197, 0xcb83b51552208e2f
-198, 0x9f306634214b44e9
-199, 0x4fb3307b0e1a7535
-200, 0x73d202d4225c5394
-201, 0xd5a2fa42f8cc8c5c
-202, 0x7b3b3e3f7b948d3c
-203, 0xa2dbc4d30d8c148e
-204, 0xd1bfc1f05a8f2c5d
-205, 0x2b00a4efa2f19262
-206, 0x9d4a05bb18647f48
-207, 0xff21fbaf0b46d13f
-208, 0x126f9c5f2132af20
-209, 0xd4b7629b0d9a6b89
-210, 0x2d61949fb3126ecc
-211, 0x30d61648763db1ce
-212, 0x9c5234d15120bf17
-213, 0x2eb0eccb6cc14c8a
-214, 0xcf18eff5ca2af8a4
-215, 0xab5fe599ea68c377
-216, 0xe47a0bb8436af89
-217, 0xd3728a566187c400
-218, 0xb8b54592b62f633e
-219, 0xe02b958f9c13a180
-220, 0x9e5f5cc85283f24a
-221, 0xbd1ab869878744a
-222, 0xb93fd6297a29c8dc
-223, 0xf22f06ee61dc2413
-224, 0xc93fe440766cbd8e
-225, 0x7459d9b19375a51c
-226, 0xd4ec87c57baa4127
-227, 0x1514d0226dc0409e
-228, 0xc6b0d7e1bd56b190
-229, 0xc0c61c73c9dbffee
-230, 0x2f1154afb48a93e2
-231, 0xd2ca05901bae0117
-232, 0x6263f647273694a0
-233, 0x94a98bf80488205b
-234, 0xcb0d63747735bead
-235, 0x9cbd4e1659932c5b
-236, 0x1807e01931b5ade0
-237, 0x1d9f7721d3067854
-238, 0xb25dbde4ec77e547
-239, 0x4b186592a39adcd6
-240, 0xe8ad5514de72a98f
-241, 0x2deac1cb096a09b4
-242, 0x6952f4b82a2c87
-243, 0xaa1590223ed83ffe
-244, 0x9baf13d08f572e12
-245, 0x83ec1bca1e724d88
-246, 0x5c61bf2222b4907
-247, 0xd950ff64ad7b956e
-248, 0x36bf5e992bf1f211
-249, 0x75ad67249d7a6c35
-250, 0xeb12dcef5c2bfe7d
-251, 0xc508da925157e39d
-252, 0x91cbd7491ea7f70e
-253, 0xf10c018ec0b0e55
-254, 0xeeffb21fef1e87f1
-255, 0xe31692b834d067dd
-256, 0xd69bbafdeb5c0d15
-257, 0x41358dadb9260eb1
-258, 0x5fa3c67d353cd6b2
-259, 0xdbb743cac20b2eda
-260, 0xe7877ba98b2bfe4
-261, 0xf14d679436fd2dcf
-262, 0xa313e39059d62afe
-263, 0x7eaa134c761a6183
-264, 0x7719af9ad1fecaec
-265, 0x533f921a4702d433
-266, 0xe072f9665ec3a3c8
-267, 0xba89560ab4ba08fa
-268, 0xe94f0aa266e56d53
-269, 0x774b84bcb152afc
-270, 0x787c9517e589748d
-271, 0x3831a5303adfd362
-272, 0x19cb20184a4264f8
-273, 0x9bc5e99e1773700e
-274, 0xed323bf38642f651
-275, 0x860868c0eba789f2
-276, 0x8c1602ffd9a5621a
-277, 0xe298d8fc74e146ce
-278, 0x3181a2083c76037f
-279, 0x27942fd6842079c0
-280, 0x38fe8c0406516df
-281, 0xd211a4a42857bec3
-282, 0x56002508b351879d
-283, 0x2472ed93614c7e99
-284, 0xbcafdaadc0f77b7c
-285, 0x86becbd3e5303107
-286, 0x930251d84de72320
-287, 0xea79aa2964954052
-288, 0x6dbc5e63b50b1724
-289, 0xb098535ed4bc7372
-290, 0x6490d6d8541fb656
-291, 0xc738f6ccb4b7076b
-292, 0xd69ee4fd6ce63026
-293, 0xfa98e9d78a628338
-294, 0x9c30b63a70d607b6
-295, 0x8d544b5d224a25d9
-296, 0xa051f7fe38445228
-297, 0xf6931861338a00f5
-298, 0xecd71cd64b0b5dcd
-299, 0xdbc818e7126193b
-300, 0x3aaaa032aad8199a
-301, 0x6fd68a3818e0c439
-302, 0xc82a651ba9ede8c9
-303, 0xe6d958e267017187
-304, 0x73a9eab64de651ae
-305, 0x5a6757f7f222bb3c
-306, 0xe62e7cca6bd17a32
-307, 0xc4f6c31f528dd387
-308, 0xdecd8b663c995773
-309, 0x69a21dedcbfef9c7
-310, 0xb33f8ac00f17b6b2
-311, 0xe32b3c962d613ba3
-312, 0xa9c317d026600d41
-313, 0x901d971c49671213
-314, 0x46c3f3d35db8808b
-315, 0x1336297232af9791
-316, 0xed88d9242e11edb3
-317, 0xc70c48843f54af0
-318, 0x611062a0461deedf
-319, 0x7e3183514f127f20
-320, 0x7b549d10bace1c47
-321, 0x6db523d19d0a7af3
-322, 0xf6e677e5222a21a4
-323, 0x28e5188ba7055c32
-324, 0xbe7b41d2ce539c4f
-325, 0x5c085a18c3b7bbe0
-326, 0x209cf345b3c3b06c
-327, 0x79ca5407dd486857
-328, 0x8e07ac4c65338ccd
-329, 0x56dd5372249cadad
-330, 0x27e0b07863fa27ff
-331, 0x78dec95d299a8699
-332, 0xbd5d71253b73d456
-333, 0xbf83b6cedd205e9
-334, 0xee2352ee69aa68e
-335, 0x4b14f253d684cfbc
-336, 0x12ffa5d5f8a34bec
-337, 0x2e38346fbc793f67
-338, 0x2ab5862872b4850b
-339, 0xcbc8aec1e2bb6760
-340, 0xd79ef783845cc329
-341, 0xdbdcde91e1685704
-342, 0x29880643aa1095e4
-343, 0xcd5ccc1fe9a616af
-344, 0xc7b6cdc4a43c132c
-345, 0x7b08597fdec7fc9c
-346, 0xa01ab3827e120a16
-347, 0x89ce37de99ca7748
-348, 0xb4644823ea6b90d5
-349, 0xdbe189861c409209
-350, 0xbfeb614759981b60
-351, 0x48c2c3a6d2419755
-352, 0x1aa1df0e99b3417e
-353, 0xb9f061bf98c0da28
-354, 0x8bce2755a0b5b8ae
-355, 0xc9bb2ff33d60b3e7
-356, 0x6abcbb1ea0d3a575
-357, 0x983a3c16a0e5d6f8
-358, 0xa122e616797ccdbe
-359, 0x751dfe60252a01d0
-360, 0x8d1bcbbde84f6a11
-361, 0xb6bc4f2942ba0e57
-362, 0xb298977a4bb20e12
-363, 0xcf658188dd931722
-364, 0x39735757b19c90a3
-365, 0xc2fcf1df99f1b7c4
-366, 0xd42c50f6a912aaea
-367, 0x95d0cb8a953965c4
-368, 0x75c7d03289269f25
-369, 0xd8d96184031fb36b
-370, 0xb3b34b5ba8bac75
-371, 0xcfbf16d241e46f8c
-372, 0xec465e59019b6f6f
-373, 0x4051ce0bc2562a63
-374, 0x859f05ce7b75da05
-375, 0xf2661ef2e3c733ef
-376, 0x8067f432dd5af0c4
-377, 0x6e8542a346911713
-378, 0xfcda2ac6aa45ca20
-379, 0x571f23fdacb25fe2
-380, 0x2546f5badf7adb8b
-381, 0x929ebe6fbd330e2b
-382, 0x9d41d6ded9facbeb
-383, 0x4cf9d9da6c125106
-384, 0x495d5708443faa36
-385, 0xb0023a41a6057e59
-386, 0x37fa1cd9ce66b20a
-387, 0x96a376fca4aff5a8
-388, 0xc22469c4a3e1ea85
-389, 0x5ab79b721966249b
-390, 0x2124be452f7d4ca4
-391, 0xe71bb882b954ca11
-392, 0x322bdcaf9c7b0efa
-393, 0x4c99c8753878439f
-394, 0x3ffd6caec9f9ac49
-395, 0xfba842dd40a3c72e
-396, 0xfd93517d31681d77
-397, 0x44c139a74249a128
-398, 0x828a145610684c8
-399, 0xb53696f802522b6
-400, 0xa2da2199474d079a
-401, 0x739e508fbbdeb714
-402, 0xe75c4734a7c95f94
-403, 0x5c22c226f2bd8487
-404, 0x7108fa6b99b0d72e
-405, 0x3c60b40f6e4bebde
-406, 0x395150555d56dd18
-407, 0x13246a6e4d795fe3
-408, 0x27dca990fb678027
-409, 0xc5a92c32724a7373
-410, 0x30fed89f4171a817
-411, 0xf7f7810edea2e7eb
-412, 0x46e930eef5351212
-413, 0xe1331cd8a678dc66
-414, 0xd4cc0a5f96a72457
-415, 0x2559f8d286b1da16
-416, 0x73831b2f6e4a4ba
-417, 0xd929ccf267504761
-418, 0x8a7a1b357f8bbc38
-419, 0xd5e0d3e200d0d633
-420, 0xc2cc05cc3ac5abb
-421, 0x75b8f78a06ca465b
-422, 0xeaf1d6aa9c0baef3
-423, 0xa6c9bc3dbe45e62e
-424, 0xb1496074b4c338d7
-425, 0xc18ebb892108cec
-426, 0xf6cbbf4cd0f8f9ba
-427, 0xd73759407ecbdcf6
-428, 0x54dc0805c85a3b0c
-429, 0x4ba3936d6be048f3
-430, 0xa3fbea19803cf35
-431, 0x78b1d3a837d4bed
-432, 0x6ed09ac2c177453b
-433, 0x16134c4e8b30f6ba
-434, 0x94718ce4868f01a3
-435, 0x612fa336da82e66d
-436, 0x5d8833c9483b235d
-437, 0xf5c72d4883bed9a2
-438, 0x2a6e27d1ed337134
-439, 0xfba250d6b9cc0d2b
-440, 0x432f8734b61e4366
-441, 0x45e8becd5ccb4f32
-442, 0xffc7d68cb343170a
-443, 0x247cb9a6b29b1a35
-444, 0x89876df3681dc65
-445, 0xd1e646c49aac769b
-446, 0x4c3cd721635602d0
-447, 0x5139344709c749fc
-448, 0xc5130d981e1a6b14
-449, 0xff269bea082608cb
-450, 0xf45a5d57a6d4c6a6
-451, 0xc4c9f3e5398db827
-452, 0x2b3a0eacd42665b4
-453, 0x94d847d848a8e65d
-454, 0x1a8aff186e1d75d2
-455, 0x6ad986366c54a242
-456, 0xbd832c0607523e7e
-457, 0x973064c20c31842d
-458, 0x34d0513e6d602f80
-459, 0x91b3c812f83392ed
-460, 0x4c49ba38b6a4cf90
-461, 0x82e3370e1c5ad5d4
-462, 0xa29a01fa53250a13
-463, 0xbe8ed1e615a1ee6a
-464, 0x17fb15941a9fe6b4
-465, 0x84aea1c0138fb970
-466, 0xab065efb4558003d
-467, 0x3345b340257a2551
-468, 0xfd2ebda1048c0dcd
-469, 0x2aa72fce0cb23982
-470, 0x9952f9363830ff6d
-471, 0xdb240e279cb7f901
-472, 0xb4a1e7b54206aca4
-473, 0xe13bdbb980623f25
-474, 0xd989f009368f8a9a
-475, 0x7084b7695149660d
-476, 0x55b92a3f139c7f1
-477, 0xdb43c75c633debd0
-478, 0x94e362574c70b9a8
-479, 0x218a1a06d9223f9b
-480, 0x82f3c3808f86bb95
-481, 0x63e9de6cee4b77b2
-482, 0x3bc5effa36bb166
-483, 0x8369cbe5fa0ecab
-484, 0x2a5808b4d7bc8572
-485, 0x6856e29700de99f5
-486, 0x107e86fcfd4a48d9
-487, 0x15c9ee6528c1c223
-488, 0xbf7318d4206c5e75
-489, 0x15d7a6aa9343c9e8
-490, 0x93419fe0ee3bd5df
-491, 0x916c7f75ededdd53
-492, 0xe89d6230690f74f1
-493, 0xf92f96834e0eb27
-494, 0xed5adc06c305adc9
-495, 0xf656fe40e7ecb4d7
-496, 0x32a2d3eda46114b6
-497, 0xb3f17867d23c75e2
-498, 0x2a2cc838c4d89c33
-499, 0x413df7052f8866e7
-500, 0x373bd93e91bbed18
-501, 0x78c8e5aa1e1e2dda
-502, 0x6bd362f6be6d572b
-503, 0xba1926efd387aeb5
-504, 0x3b826b77ae3e53fd
-505, 0x383cf5a66fb6723c
-506, 0xf5a4e1dded64d931
-507, 0x76d9843a304729d3
-508, 0x205b8753b6d309f0
-509, 0xd2a68ef67d8e7758
-510, 0x60d517f325411c0c
-511, 0x37a3bb4950cf08d5
-512, 0xea3d4f95542ffe2d
-513, 0xa88708db07fb1d34
-514, 0xd96555e1194f7ee0
-515, 0xdd046e642b59fa51
-516, 0x18ff34e73582d46b
-517, 0x7ed73af03535c5fe
-518, 0x8ffd64801d2c5187
-519, 0x7134902903c9cfe2
-520, 0x74fa0b238ad1e1ec
-521, 0xa220ff0032395fd5
-522, 0x4ed0a7a2d9c3a064
-523, 0xb02cb878b4c9a04d
-524, 0x8437cebea5ae2bec
-525, 0xabcc162a0027aefa
-526, 0xc8e86ab8f5c09011
-527, 0xc28dfaf764ec07d4
-528, 0xb19127d64ae5db18
-529, 0x857cb1b00ac7fbc7
-530, 0x173a441c4b494aad
-531, 0x255af1a4d50952c3
-532, 0x87ff01c7d0139add
-533, 0x489b15e4c97cfcde
-534, 0xd4abbccecfb67239
-535, 0xa1a2912ad34ac4fb
-536, 0x94b7f12e10bf720
-537, 0xdb8840c295333634
-538, 0x5a29aab5b359f2c0
-539, 0x630352d282b695bd
-540, 0x399f00854d3fbdf3
-541, 0x19e917e0eb8bf070
-542, 0xa464b4dc93d1fe7d
-543, 0xf152d3cdecbd7647
-544, 0x517907b570a6b082
-545, 0xfeb06f4bd978e7bc
-546, 0xa22859ad14c0f183
-547, 0x33c11e90be9721e3
-548, 0x8394f642b5a40d7d
-549, 0x9525633e7e60ab73
-550, 0xf97401c9b4b96001
-551, 0x3d78ce1ecf900029
-552, 0xa85791d9754a2765
-553, 0x16e77aadd9a30946
-554, 0xc91d4defe72f39f2
-555, 0x2fb67bd91edc4b51
-556, 0x95d635e95b468fa7
-557, 0x28b81869d1739e29
-558, 0x5b098fa22cb1747f
-559, 0x6544b8704bd2400a
-560, 0x91a64f9ec6e93245
-561, 0x2b46ba92268db263
-562, 0xbb52d7758efd5416
-563, 0x7032adc08e6d39da
-564, 0xe9d3bbefdb61feb6
-565, 0x2d603389c757996b
-566, 0x5871ed32ce17d042
-567, 0x31d622a6b8438f70
-568, 0xc71af17db6bf7aed
-569, 0xe419e3c6fbe86530
-570, 0x648471d670f18dcd
-571, 0xd13f9e25078599ed
-572, 0xdaf86e56826d07a3
-573, 0x3c9374e4420a8580
-574, 0xcd75b12ad6d8d9fe
-575, 0x2d4530f6e2b93ca3
-576, 0x303bb663ad4ca963
-577, 0xf8caecede4436b61
-578, 0x315a8124669a907f
-579, 0x1c18d130a4b93836
-580, 0x9e0b83663631562a
-581, 0x400059c1ce071c7f
-582, 0xb27f7f67e7cbd970
-583, 0x6b446e8c4866f3d0
-584, 0x4ab1755d2734121c
-585, 0xb9fc8e017d89edf2
-586, 0x3a9aa7f50355c0c9
-587, 0x899fece06a169b2e
-588, 0x19d7d7088db0b27d
-589, 0xe4f8862ca8f6b87e
-590, 0xceaf0d6ab4ba624d
-591, 0x318965c56f79886d
-592, 0xb1840d9bb60b720e
-593, 0x387427e7549150ca
-594, 0x9be3edb621a5d2ef
-595, 0x9758993cca6a481
-596, 0x3733c5cd48a1590c
-597, 0x9bbe26951c666fb1
-598, 0x74c7e89fefb4ba59
-599, 0x6aa490a23907053f
-600, 0xa62febef1e8d7300
-601, 0xdbfb07bbba2fd4cd
-602, 0x11ee9e4bbd4f358
-603, 0x6b40912657c7f02f
-604, 0x8d56c1a9216714bb
-605, 0x7fcd86985949c2f9
-606, 0x706bb172d5677f2c
-607, 0xfb657efea1331957
-608, 0x6e3032f72a3fe367
-609, 0x509fb8c5b618a18e
-610, 0x3599e957259222e7
-611, 0xaafc78bea53c9102
-612, 0x404addaf7ac55279
-613, 0x97db28b3b0a2dddc
-614, 0xd3f5b151a9f5aefb
-615, 0x1a6534a9be80a19a
-616, 0x78f989eb80e055b7
-617, 0xe0200fe015112dce
-618, 0xfbe67decef6204dd
-619, 0x662fef92c8e00970
-620, 0x9a7838962250f5d7
-621, 0xac0eabb1621567b3
-622, 0x1874cf715cdc5daa
-623, 0xd3281a25a82ceecc
-624, 0xd8ac0e497b11156c
-625, 0x3c8bf98f8210af89
-626, 0x971973ff9d428a3f
-627, 0x1af47276bc157e63
-628, 0x671cd5e661ed0a05
-629, 0x71b8ffba9b976a0
-630, 0x8763f1fa85c5f5d5
-631, 0x61f3c56f3441aad4
-632, 0x86482f5e90362e3c
-633, 0x8e9d9aceba401c48
-634, 0x51d916579d19d42b
-635, 0x67bdfa28310ad3c7
-636, 0xb9ab819d6a00add8
-637, 0xaa12cb0ed2d507bf
-638, 0xc636190dfc7f6d43
-639, 0xf3f1e6c104c5e782
-640, 0xaed0be2f07ad4313
-641, 0x1d782d74661278bf
-642, 0x58e6501bc7e61fa2
-643, 0x8ca4ad0e02d7fb42
-644, 0x8afc9e9fe83d4b78
-645, 0x72cb69cf4abf0b1d
-646, 0x7601a7b3500d474d
-647, 0x97fee7da53b533b0
-648, 0xd6ab646f53c0e19a
-649, 0x6480f60992f2fcc0
-650, 0x64ec7590c60a4c00
-651, 0x3ccab37f11acbe91
-652, 0x9ddd546f201299fd
-653, 0x9a0dc59d0b545d96
-654, 0x8c5f366bd21664f5
-655, 0xc0af97b445bfc5ee
-656, 0x29762536dc00c3fc
-657, 0xfc30927fd8f1c257
-658, 0xac9aadfced7d59fb
-659, 0x8d039f87658a29cd
-660, 0x13a3d73580eacf6f
-661, 0x80b80e0adcc11ac5
-662, 0x1e53c21e639f9d08
-663, 0x8a73352dc442bca7
-664, 0xec7cb2fe0e6b0100
-665, 0xfa5e63f403ac3f33
-666, 0x493d9a0018185f8c
-667, 0x1b1d1f41c6cf5cb4
-668, 0x95b4caca3e2500a7
-669, 0x4e759e6f89f62f91
-670, 0xd0a76a3198d7c05f
-671, 0x86eee6259cab63b5
-672, 0x1daab21067011b59
-673, 0xd02d9236ebc91b38
-674, 0x693e17ac2b70e1b7
-675, 0xceb5899aa14d0f86
-676, 0x59ffc317faf17ab2
-677, 0xce94f02892a0fa30
-678, 0xf7c9d6f9e753737c
-679, 0x87258cf7ff6a29b5
-680, 0xb39fc8ea8aa52a0e
-681, 0xadd4b4e73af1103f
-682, 0x511f423730b25a4e
-683, 0x7f673288e53502b2
-684, 0x9aa499e3b6295919
-685, 0x83841ad95e6a7a6
-686, 0x6e549a2457a850c
-687, 0x4763220b923113c3
-688, 0x99737bb550aa5049
-689, 0x89eb31b3f707c4
-690, 0xdad5331dda8a58d3
-691, 0x5f1681518d5a21b8
-692, 0x258a0b9b24110918
-693, 0x8854bb025009fa21
-694, 0x7ac331fd885642af
-695, 0xe520f0e9bedf0bf6
-696, 0xc9419e8801aa2afb
-697, 0x356fdc0fc3702b37
-698, 0x6d6a25f39fbc9524
-699, 0x930f65c4dbf8ae94
-700, 0xa73d7bbf8c19c4b3
-701, 0xe473f700513139fa
-702, 0xfef8f0e84c521bae
-703, 0x88525351995576a7
-704, 0xa156b646ab95f272
-705, 0x1a46ff3b9ae7e723
-706, 0xf6d82b8bd9f2a80
-707, 0x837b8127d8f39ebf
-708, 0x1f8e120ea11fc9bb
-709, 0xbd0918421430f8c9
-710, 0x4ef121a688d130c7
-711, 0x3fef66f1cf180b77
-712, 0xa92070bdc6a0100
-713, 0x2444dcbb4853c174
-714, 0xe46b7d6234504df8
-715, 0xe5ac8fd968a5d1fd
-716, 0x988828d885f04f30
-717, 0x9730c37b69f3d963
-718, 0xdb9a0d16bf0a2aab
-719, 0xe75d00b3681941b9
-720, 0x518421d62db82da0
-721, 0x4da04c94268c1dae
-722, 0xdcf2635a55b7da9e
-723, 0xb679d8206c55a04c
-724, 0x1fbf58865fec1e83
-725, 0x53ca7cc07c0e5785
-726, 0xd18eee3f5b57c813
-727, 0x9fc8d328e41d1299
-728, 0xb2231521e026e15
-729, 0x1a7e2a8df269acde
-730, 0xe5f547b160b0a6de
-731, 0xab01e7130bd70c14
-732, 0x82a051680f661a75
-733, 0x479da77dd9686ca2
-734, 0x1417cc197738b272
-735, 0xb65b5ced585a8186
-736, 0x40b5a74813e7a05b
-737, 0x55481e0f404fc2c5
-738, 0xef1ca09a2640c44a
-739, 0xa0f1d37ee2db47cf
-740, 0xcabb0c8e551f0587
-741, 0x84227dd83ad941ef
-742, 0x7b47691b6e8327d
-743, 0x4fe615394f53d6d2
-744, 0x60bca7e568f65c80
-745, 0x8676b74f2d5600f4
-746, 0x70f256171f1eb9b1
-747, 0x6b1d25099f80e1fd
-748, 0xd8e77e8a67ff3338
-749, 0x3ec375feb7727aca
-750, 0x26b9ad4afd4be26b
-751, 0x849e6f9bc5ec636
-752, 0xa34e3fad187c089f
-753, 0xe369ba87f04ecc37
-754, 0x83c6e1c3985cab4e
-755, 0x6ffc032379a15336
-756, 0x654645504b159afc
-757, 0xabc97562087edfad
-758, 0x4633765a9f068fe5
-759, 0xa226c586394d348b
-760, 0x7034d9fd40133a22
-761, 0x89e1d142a1a20097
-762, 0x7a3e1387a5ecdf70
-763, 0xf0ae75084f0a1bc4
-764, 0xdcf97778ae782977
-765, 0x87996a44dbac128d
-766, 0x94b102ac15479072
-767, 0x9d670a01e10c48a0
-768, 0x8f977a03176d0cb1
-769, 0x8522bdbed25653c
-770, 0x8f2b64a9cd6b5483
-771, 0x86b2beaa71c92fbc
-772, 0x40f896707639f820
-773, 0x40e7df1535fc03ad
-774, 0x1d34c491e13debde
-775, 0x862d5ad393292476
-776, 0xd33ee4efdd4b14d9
-777, 0x63ce5c7643b85ecd
-778, 0xd28a7fe0700fd15
-779, 0x8c3536390f9b7b55
-780, 0xfaf87a9036dd0265
-781, 0x187e261c23b454a5
-782, 0x95362150f08e5f86
-783, 0x6588c21939d9521d
-784, 0xc7cee242280b7526
-785, 0xc1b8f83462038485
-786, 0x68c2f342724de8d6
-787, 0x35c283dbca3c62fd
-788, 0x556c441e9fdc5cee
-789, 0x898ba42c4ad3f5ba
-790, 0xc654a072fe9ce540
-791, 0xcc2da7cabdc658d4
-792, 0x518b6badf9c1ba7
-793, 0xd43b259427de48cd
-794, 0xfe7e74d4415bea8a
-795, 0xdee4cacb454d92c
-796, 0xdfb09dde6d6c3000
-797, 0x5c0d4ce2c7a8d426
-798, 0x29ccf2d288f4de4a
-799, 0x4106e7f40d2597ad
-800, 0x3bc376950bccf69
-801, 0x65b74e149d1066e3
-802, 0x751d008e4f823e5e
-803, 0x4a3b9a34d8ece205
-804, 0x372e79ed6d9461fc
-805, 0x78e08cab6244f8d2
-806, 0x7d273315b6d9250b
-807, 0x26c401cb05f556b2
-808, 0x3324d95fbc93408d
-809, 0x14fb55fb83ab0a8a
-810, 0x7ea7efcddd0a747f
-811, 0x150a110bd5cb1b57
-812, 0x1122b31f5d20ad23
-813, 0xbd996a43507da1
-814, 0x6d11fad057e5a75a
-815, 0x22a4d3223d77684b
-816, 0x349973b5dda3d3e8
-817, 0xe4dab5aec267e32d
-818, 0x371cbd61bbb7858c
-819, 0x7e49182abfc0fc68
-820, 0x937722b126a7d173
-821, 0x29604490ccbe6611
-822, 0x6c8b230bdcc8dfaa
-823, 0xb1c267c94d4550ee
-824, 0x80d1fa6e33cde91f
-825, 0xe205a132f35af0a7
-826, 0xe4e8e50899fea5c8
-827, 0x3a6517d09206dfef
-828, 0xeff4e4f8efd0a4ba
-829, 0xd8df88c992b3df74
-830, 0x5b0df3c40071c0ac
-831, 0xd44a062781f833f0
-832, 0xef35653edcb68251
-833, 0x21f879df2bd3cfe0
-834, 0xdb5e837565891932
-835, 0x6da15316efae41e7
-836, 0xd33cdc0d05f8dd6d
-837, 0x3c6588502a24be1c
-838, 0x3d25da26bee94818
-839, 0x79979979960d383d
-840, 0x8a20663424f816ec
-841, 0x74c587d5824ee15
-842, 0x145f90c6b342c489
-843, 0xe2c2d15b8de95387
-844, 0xd9deaecc24e84ede
-845, 0xce52add2f5c3ea3
-846, 0xd1da2db8cca0014d
-847, 0xcbeed544f8791232
-848, 0xb55b421de003edf0
-849, 0xde102a5a87a9a5da
-850, 0xd74fc9d34c964bd3
-851, 0xda7e1e271d197070
-852, 0x1167b33a6bad0d13
-853, 0xd35c886fd0e28798
-854, 0xfb3334085bbcef67
-855, 0x88f4957ddc912f99
-856, 0x7c1b0e356835cffa
-857, 0x8c737bc009bf5a1c
-858, 0x44edc242bfd88b0f
-859, 0x391f8b5db15f8b01
-860, 0xd44794c8a4245701
-861, 0xefa90e38ba4a2f6e
-862, 0x597f65c886e697b4
-863, 0x28972f6be3ca8677
-864, 0x18a487b5e89a9dbb
-865, 0xffb15ebcb8a15fb1
-866, 0xa1f64108b7feeab0
-867, 0x36fc88b440612004
-868, 0x72a723294ba9af87
-869, 0x1a38da0ff8f187d7
-870, 0x529d7f6cd18f664a
-871, 0x6a5941953b4732c7
-872, 0xe91243bd8fb27a03
-873, 0xb80c55de03262828
-874, 0xacb9183e5b28a8d0
-875, 0x4c4ca12eb3d5d2e5
-876, 0x758635a20eb18211
-877, 0x211e03e90d6bd001
-878, 0xe36e20fbf0f271b5
-879, 0x4daecb676fc64ebd
-880, 0x8f1e82c4dd582eb7
-881, 0x6e3c35a21bca1b8f
-882, 0xf3c2a69420f159e8
-883, 0x2cda4d630caba89f
-884, 0x4c93f3f96360d308
-885, 0x4192046fb5e9d801
-886, 0x349f2b172f49599c
-887, 0x7bbff8dd8b480e6c
-888, 0x83b33fafc4388bf
-889, 0x9a5440f806d9d1b
-890, 0x8d6b62101dcfe51f
-891, 0xbc7dd6987af227ca
-892, 0x4338e67e0d6ba6a0
-893, 0x4a23deabbb5fc3ce
-894, 0x9f8edc91e6356eb8
-895, 0xf6b723dd2dd5f80b
-896, 0x35c558dd3443021d
-897, 0xa559dd33c2cf594d
-898, 0xa50ceeced7a82783
-899, 0x21107b581db4ee9f
-900, 0x13e8dd9302e8c97d
-901, 0xbd8491f437e57ad6
-902, 0x72f4c2a57c06f35f
-903, 0x518fbb95071d8d7d
-904, 0xcdbbe8d47f9b13e9
-905, 0xe8152b0f387251cd
-906, 0x411070a4f345676
-907, 0xc589c285b962389
-908, 0x8b0eb9e285844319
-909, 0xe2b007f446a21b38
-910, 0x868ffafb958a6c40
-911, 0x19ccccd559408de0
-912, 0xa7666f366db0ae71
-913, 0xd78c5f137da6dbc2
-914, 0xeeecc913fdb9af03
-915, 0x7a5afb2f3d54a396
-916, 0x64fadf73d7ba200b
-917, 0xaa1b82c6b4b346aa
-918, 0x9a312d9482244a60
-919, 0xadb3c0a30f68d0f4
-920, 0x21eee75a717008c1
-921, 0xcda2779023f54837
-922, 0xea3c577c6d7783e2
-923, 0xdaae89efcd431a13
-924, 0x9a6102d2dafaded8
-925, 0xd29443448e01734e
-926, 0x6b968e58c3d5bcd0
-927, 0x13949d0c5c0f9d19
-928, 0x7053eef909932489
-929, 0x49fb97e33c279171
-930, 0xc955e4854e254d03
-931, 0x3300cb752a7834fd
-932, 0x8319585b09da0928
-933, 0xd35c64e4ce23a294
-934, 0x9a41d980ba1774dd
-935, 0xff570729be1f3f02
-936, 0x3f68ae1c3e690a41
-937, 0x6f58a3e861159e42
-938, 0x111d9975e94f0004
-939, 0x276d3ea0ff1ca6c
-940, 0x4209cb1f5ca1c594
-941, 0x71699dc4c58f1bcf
-942, 0xe0288bffc5a27a2e
-943, 0x6c0962c36163c4f5
-944, 0x3a8ad088b4fd204f
-945, 0xb945dc7721092d36
-946, 0x315f4c1738bdf365
-947, 0xe07ddd7121cafb70
-948, 0x626fadaee66f331e
-949, 0x6fe3f71dd5e7ebe1
-950, 0xe3cfb6b53bd8713c
-951, 0x30f5b732f7070968
-952, 0xce2f941f93b957f2
-953, 0x116897bad7f55bca
-954, 0xb9d2c4a98826c3ff
-955, 0x9672c28485d1c95c
-956, 0xd0656535c3df1e44
-957, 0x15294f18a999528d
-958, 0x82a98977ad1e933a
-959, 0xddd17b6eeced5f84
-960, 0x9901a04270fa2d5c
-961, 0xcd2a8d3ab69a0c62
-962, 0x706bf86127a4597b
-963, 0xe614aa96ed708afb
-964, 0x7f6361ae8f59987
-965, 0x6a355657b59c4874
-966, 0x5211dca87f30cdd
-967, 0xa21cbbc602f58ee4
-968, 0x68dff176c9b02a7b
-969, 0x68f89bb7bca83c5a
-970, 0x229cb884febc7e56
-971, 0xce4f300cf6b70884
-972, 0x6ad3f343c76c5e0c
-973, 0xb059a099f121222e
-974, 0x9e990641d81a63b8
-975, 0x5564e79afe160ecb
-976, 0x2a9fa9c590511dcb
-977, 0xca36751ba40931da
-978, 0x23a332a9fe1104aa
-979, 0xdfe116c321547662
-980, 0xf484bfbe18f2c1cf
-981, 0xf8f2b4adf2d1ad4
-982, 0x4308800511929ba
-983, 0xe2773c41e0082a51
-984, 0x6b74adc21bac6b3a
-985, 0x1faa6a3704bd1b66
-986, 0x89e3e641298e87cd
-987, 0xcb2f118548abcdc3
-988, 0x690e34dfb4153ab9
-989, 0x103d668edb5f7e88
-990, 0xb29d9f22b3b1d4a4
-991, 0xc4ce3be9022b314d
-992, 0x1cb3d5af1306da15
-993, 0x8236da372d964cce
-994, 0x79188ac299f06c2b
-995, 0x953dfd978aad2545
-996, 0x6058e1066e7285cd
-997, 0xf47307b50589e391
-998, 0x2923873ecd9c4d32
-999, 0x4c44d61328ac5e4a
diff --git a/numpy/random/tests/data/pcg64-testset-2.csv b/numpy/random/tests/data/pcg64-testset-2.csv
deleted file mode 100644
index 779761d0f..000000000
--- a/numpy/random/tests/data/pcg64-testset-2.csv
+++ /dev/null
@@ -1,1001 +0,0 @@
-seed, 0x0
-0, 0xd4feb4e5a4bcfe09
-1, 0xe85a7fe071b026e6
-2, 0x3a5b9037fe928c11
-3, 0x7b044380d100f216
-4, 0x1c7850a6b6d83e6a
-5, 0x240b82fcc04f0926
-6, 0x7e43df85bf9fba26
-7, 0x43adf3380b1fe129
-8, 0x3f0fb307287219c
-9, 0x781f4b84f42a2df
-10, 0x36dac886f4232c6f
-11, 0xa32006a96a8d46b
-12, 0xa56e609a788ce098
-13, 0x75711678fa371144
-14, 0xbcdd4619fa063896
-15, 0x5cb5c9a1594f1a04
-16, 0x799e6cc7d09bf3fd
-17, 0xda1a4b52f72a8c6f
-18, 0x374b6f698c864e48
-19, 0x96a3e4d45b8d252d
-20, 0x5fc89e7cbf7735e4
-21, 0xe0cfe37beef7efe6
-22, 0xc3467c95f4649808
-23, 0x95cbda6a3275f18a
-24, 0x3a4dc1e59bdb4172
-25, 0x47f8755023ac78b5
-26, 0xef8e166bf07dfa95
-27, 0x40065cf0fa99882d
-28, 0xbaa083ad70102eb6
-29, 0x7c88e9d1a72a8dc
-30, 0x1484e44aa83e901e
-31, 0xf0f8df78086fdeba
-32, 0x5114e38e0cff505d
-33, 0x7e04bb9a2828c944
-34, 0xb88c0de9e2af5658
-35, 0xecba992ca7e9178d
-36, 0x8b40b65347cfeffb
-37, 0xfce9281a9381a55f
-38, 0xfde34f9f228fc03f
-39, 0x8c46656aa79eba9d
-40, 0x1ed0d3f416073189
-41, 0xd7adcc20a26d48d1
-42, 0x2429dcfa355eddba
-43, 0xec100f2285aaad68
-44, 0x91a83984506e1ef4
-45, 0x4c10c0f973e3cba5
-46, 0x45d0d0ad9ab6890e
-47, 0xa52b22d88ddb6090
-48, 0x63f7e7549bf80c43
-49, 0xfb03f87e5ea7137d
-50, 0x822f96594246a4aa
-51, 0x42242b1335cd3424
-52, 0xf78652fc51ec76ac
-53, 0x24db7314bda69cc5
-54, 0xcce4cf66737c8427
-55, 0xffd70eeca33ed90f
-56, 0xc154aff2caddd546
-57, 0x59d47a8ccd59e1bb
-58, 0xabf793045ca561f8
-59, 0x3f1486708729b21d
-60, 0x76ed98409f3f9abe
-61, 0x3f0bb2cd7cedd012
-62, 0x448f78da1713ac85
-63, 0xddbae7151c1578b2
-64, 0xcf94237ec0973cd7
-65, 0x76a0657cedebac81
-66, 0x2b13b564bed7a3b3
-67, 0x47a6fc0f4604c781
-68, 0x22acf016523ae80f
-69, 0xf728771b939c13a2
-70, 0xab4aee3986c80ec8
-71, 0x61d8c8c918b3fe52
-72, 0x7a40380c747f9044
-73, 0xfaf974af2e96a882
-74, 0xb8bd56d90c69d42c
-75, 0x7cea307dda515497
-76, 0x56d0858a27ded2a3
-77, 0x8717ea17698706b7
-78, 0x6b34d0c0587e8867
-79, 0x387a8142ee80d29a
-80, 0xbba414cee59e3194
-81, 0x6d2fe8bec0e51a8
-82, 0x11d5dc961ba15ec5
-83, 0x7af1ae07932b2fb8
-84, 0xb13ea6b28d63b57e
-85, 0x7e89a6f060cf59c5
-86, 0xad1f662c4daa4764
-87, 0x929a054dec3e229f
-88, 0xf7f41c2a34920f09
-89, 0xf0eac1b75822b72b
-90, 0x24f311773d90d399
-91, 0x9c2147da3d098c17
-92, 0xa62963f5bb0f8b9e
-93, 0x97f650195285e480
-94, 0x602433fd24fe4125
-95, 0x6f17d6e3b5fd704c
-96, 0x3ad6f2cf0ffd6a04
-97, 0x73a6d93edf693e03
-98, 0x467d4e6fecdfdb20
-99, 0x6aadbba2b2f8a2f8
-100, 0xc865bae9d8713526
-101, 0xa94d7c6b462e5acc
-102, 0xdcbb47fdacd4d865
-103, 0x80aa6a71fd60cb40
-104, 0xf27ad62910288223
-105, 0x88f93784d309825c
-106, 0xf7f9a500b821c886
-107, 0x6cd6e37a5dca4830
-108, 0x57694853b9c75561
-109, 0x9c7ef1aa6b8f2c1
-110, 0x12046439309d6e40
-111, 0xee3d652c43bd35b9
-112, 0x3838110676b26d7a
-113, 0x9efd697137fa24c9
-114, 0x1eeaa149a7edd5be
-115, 0x17eb32cd212e374a
-116, 0x73dd5b7d7fd3b280
-117, 0x788e514de9649f29
-118, 0x6e2fb96fbf87fe8b
-119, 0xc736a34c7ea74137
-120, 0xa4d48bb7df0e3c51
-121, 0x25b66ee78063d37f
-122, 0x9058e087b9696e7
-123, 0xa2e6397ebdd3d935
-124, 0x394a16ba856e6899
-125, 0xe4aad4f1bc61d046
-126, 0x5e4904686af5c43
-127, 0x4e58956c61a1880a
-128, 0x7328c827d6236eff
-129, 0x29463809b511cf73
-130, 0xceb2c403cef62247
-131, 0x9ccc00f358aa8346
-132, 0x6fdc1c42421ba33
-133, 0x1111d660460f5300
-134, 0x97a4f922e55a9226
-135, 0xbc2a217152bfbc63
-136, 0x3617700c68d104d9
-137, 0x8eecc63c4a929622
-138, 0xc69cf9d8f8b45df3
-139, 0xa2a8ca8262f8921b
-140, 0x4339edf9e292f9e0
-141, 0xfe385e2e7f6e1a1a
-142, 0x5f30d1b803abc1d9
-143, 0xf123207050238c3c
-144, 0x79e3401200b54b1a
-145, 0x858d7ce163d4de92
-146, 0x5803a44cd013b965
-147, 0x17c65b0b01800940
-148, 0xc50b38bb58dcb3c7
-149, 0xe476e9925898603
-150, 0x3972fb0fa748a3a5
-151, 0x93da971efb1036f7
-152, 0x658bab8ef6082bf2
-153, 0xf664abd0de92444f
-154, 0xa2145e8039e61d87
-155, 0x28af5560cb0ee0ac
-156, 0xc1e43e6a30cefef6
-157, 0x74f61d623cc6965e
-158, 0x3ee0139a07b6c130
-159, 0x214992e8a6134c54
-160, 0xaa83b771c9421231
-161, 0x15487762c93cf5c6
-162, 0xa3d37b883fffdfe8
-163, 0xe398d2bd15c1c511
-164, 0x3154f894aedd5938
-165, 0xc7ed5190721ec2b5
-166, 0xca02cf8dcfef83b4
-167, 0xa22c6a2e5460e0f3
-168, 0x2d72e4d264875109
-169, 0xf282e30c8b945616
-170, 0xa1a286624feece2e
-171, 0x6f773be8548d3fe
-172, 0x8c6dc6f48c83c30f
-173, 0x13dc5926122501a1
-174, 0x5537f3d25d126e0d
-175, 0xdb654b8409365aa5
-176, 0x55d8f727e066e818
-177, 0x534841122140f9a3
-178, 0x4e4ecc7b2ce8efa0
-179, 0x3655d535028e4044
-180, 0x6c2ad71379f15365
-181, 0xd1f1238395ce193c
-182, 0x4ecd9ccc56595a72
-183, 0x3304220c15b60f7a
-184, 0x3726fecf394006bf
-185, 0x4523e03e39a92ac1
-186, 0x191c97036c0e20a8
-187, 0xbfbcf849ecc37cd5
-188, 0x3c6090d256b1c780
-189, 0xf7e94dd0d3e02fd8
-190, 0x83034fb1c17bb99f
-191, 0xa7be8e0eb37c9260
-192, 0x177d2c560b0b55af
-193, 0x55da4c839514e82e
-194, 0xc9b393b79b0e7617
-195, 0xe9658403d3a140
-196, 0xc86401b988be38e7
-197, 0xe82baf54ee5df9e1
-198, 0x3a562e6572a853a4
-199, 0xcb83facbed1cb364
-200, 0x4db406f08ea62242
-201, 0x9cc816f5376ab97a
-202, 0xe65a32f96a78b09
-203, 0x59e7b42c496e2c2f
-204, 0x7e3e59a4546b6b33
-205, 0xc51a371516d5adc4
-206, 0x19ba384285a523ca
-207, 0x5b998f71002a0912
-208, 0x81ee2f95f53dbce1
-209, 0x966a0c0bbf15492e
-210, 0x80f88202ff2d29c2
-211, 0xf827f45274e32733
-212, 0x66a2611b73547490
-213, 0x1b2c3c3ae80997d0
-214, 0x264a86e09c63e4c9
-215, 0x35d4bf9c9d0d89a2
-216, 0x6051e319babb305f
-217, 0xdf0d08608262be49
-218, 0xbe7aa9a7697278c2
-219, 0xac531985f79fca17
-220, 0x7ce7de0d95ba34d
-221, 0x9a03956d30de1ee0
-222, 0x8106a5873e7950b0
-223, 0x804c06b1fab989fc
-224, 0x20d5fe19357e95dd
-225, 0xf3e89c08d1841c79
-226, 0xfc93b079bdb323cb
-227, 0x8f6eb1dea40eda88
-228, 0x6e7f6b657f6d971e
-229, 0xf2b15bb03a49e9bf
-230, 0xcf7fed1aff1786b
-231, 0xe53366adc5bafe42
-232, 0x89b853ed67fc2387
-233, 0xd13dadf3828f1df7
-234, 0x2f884ffbb83075b9
-235, 0x8efd2baea4771d71
-236, 0x7872e80c946c6bce
-237, 0xcc487bc4ea869070
-238, 0x820609347e4fdd75
-239, 0xe939e3c63701a997
-240, 0xf70ed361e42164e9
-241, 0xa9f29046fce9ba8d
-242, 0x61edfa750175e868
-243, 0xb7d2424653bde389
-244, 0xdadd225205e74ef4
-245, 0xecfb9a633ee3c774
-246, 0xcbc69459f0634f30
-247, 0xdbcd82538e0785e2
-248, 0x2b272f59ad36e01c
-249, 0x601a38897a57cc68
-250, 0xfa012b9e5722d8be
-251, 0x5bce8d48277d7338
-252, 0xd1b6ca2b93483dc2
-253, 0x8b94eceb88f55be9
-254, 0x93403aea5df5da18
-255, 0x57b6fcaf351c16b8
-256, 0x70f5e54095404bd8
-257, 0x9124d47160362770
-258, 0x987ed72af8aa305d
-259, 0x71e3a8d5156f82c7
-260, 0xf788e966e86f7004
-261, 0xcf0cd5911c4bb0e1
-262, 0x3340b119d3e2f28f
-263, 0x9952106be6e3bf95
-264, 0x99a6213e19fe9d1a
-265, 0x4f0d3811a8a5d481
-266, 0x62d732ee5f975dd2
-267, 0x3abc8340ab323ebd
-268, 0x15da761a2518c843
-269, 0xb453de7d4d15b261
-270, 0x4adc2d7cc2cc0049
-271, 0xcc9b7fa135c7dba4
-272, 0xa14857a738db2b52
-273, 0xce036b49e28c19c7
-274, 0xaee7e9fde421bd4c
-275, 0x15dd298915099a9e
-276, 0xa3fa6550b639b66b
-277, 0x5f27c59b035a6532
-278, 0x2eef2e6292288715
-279, 0xabd211c514e3699e
-280, 0x6d7bf9b33f8b09e5
-281, 0x91ff83561361c170
-282, 0x8f8e309797a91e4f
-283, 0x2b11ef1cedf1036b
-284, 0x6fc36ed305d27972
-285, 0x7e294e03a91eb01f
-286, 0xbe16009d8b2f38a4
-287, 0x2bf69c7b54e60cea
-288, 0x860079a07fade829
-289, 0x8f0ce6ae4c90d38a
-290, 0xab10e5f8ab4835fc
-291, 0x49ed43ddd4ca0a76
-292, 0x201eaa53b6df058c
-293, 0x2d9a4fdb16f6c1c
-294, 0xd3406193e1dd0760
-295, 0xad38857b542ddb6a
-296, 0x52ec1e450363aad8
-297, 0x6e65469594331886
-298, 0x4b027ce344dd6660
-299, 0xbc801654b4a1ccad
-300, 0x155be4bc51328b2c
-301, 0xa9a1965f9b2b5bdb
-302, 0x386b8dc34de0889
-303, 0xd60ee4b1b9cbb057
-304, 0x6c1e60b6914c4876
-305, 0xd07bf84dc30bf653
-306, 0x362d5b19b3f4f7e9
-307, 0xd145b8fef9a6a3d2
-308, 0x5c401126b505dd09
-309, 0x8f5d1d4446f9cb4c
-310, 0x725618359f1a3e38
-311, 0xaedad9cf455de2e5
-312, 0x7f7e4e549b4bde1b
-313, 0x35002b8e995f815
-314, 0x9aecaf8f393cade0
-315, 0xf346a49595886d86
-316, 0x459d5a9e92e9c149
-317, 0x60885682c3d6ff0d
-318, 0x90f5e985e08bfc3d
-319, 0xbf413a432e1a1b81
-320, 0x789503524aa48aa9
-321, 0x7880e5bb484bd49e
-322, 0x7426535c324b7176
-323, 0x190ad37f84acba3
-324, 0xbd52510631d4f5d7
-325, 0x98f794ad565c986d
-326, 0xa0ea374e66c0bf56
-327, 0xd683fe7102145335
-328, 0x9b3dac61db2f2930
-329, 0x470d31e3096c2450
-330, 0x1f445f8292f6f3dd
-331, 0x1687ff432def56a7
-332, 0x887d4e6617525278
-333, 0xcd81ce8cc70b13ff
-334, 0xaadbc4c3525c18e1
-335, 0x96d81490c362b621
-336, 0x128b95092e36796c
-337, 0xffeffbed0980cdb7
-338, 0x3bcef6c52b36d07a
-339, 0x400879c888eeabe2
-340, 0x373c9978059787d
-341, 0x35979fef9e20050a
-342, 0xf4581367f3fc43b
-343, 0xcec7b91352ed0186
-344, 0xa7b06e92b765203
-345, 0x6713f0b11fb9f296
-346, 0x95c53b86deafbd95
-347, 0x3694844a5eca42df
-348, 0xd0f334ea2c650574
-349, 0x5ae6771044110ddf
-350, 0x9f61d9087e7d36e5
-351, 0x28f04e48625e3e5e
-352, 0x6164d6b5445cf130
-353, 0xa36b5c2de27084be
-354, 0xa099a43d5c5f21bb
-355, 0x706edfb05fbe8b9e
-356, 0x7aacffffc81ebc3b
-357, 0x6f49121baebd0e6a
-358, 0x41fda7ba6df8f4cb
-359, 0x1bea4b596dbac5ac
-360, 0x71dd0261d65b02c6
-361, 0xad7f50624c15e9c9
-362, 0xf7c4eeb84d4866b6
-363, 0xa5e23dd382f48bdb
-364, 0xe6ffdf875d534bfa
-365, 0x40104d8444f75a7c
-366, 0x8218a42f24a88364
-367, 0x9d3f9382759cae86
-368, 0x101d7adffbd9ebde
-369, 0xf9fe3578d6b739dd
-370, 0xd23c47039e882eb2
-371, 0x37fc4fff590191b3
-372, 0x2a672fc8cd3e0cf7
-373, 0x995b8faabb4332c7
-374, 0xabc6117aa665a743
-375, 0x3fc49d11869352ea
-376, 0x4ccc3cfa9540797f
-377, 0x111c57f059fa3ef4
-378, 0x44a737bac79496bd
-379, 0x37924823edfe0774
-380, 0xa4d8ee07ab241d02
-381, 0xbb0bf46c50f349ac
-382, 0x4db0a8506e22199c
-383, 0x93239f377c85ba51
-384, 0x56f51e3970e409f5
-385, 0xe82d51ebc177609e
-386, 0xec866d8b473eaeb
-387, 0x42f8018bb955abed
-388, 0xf58ba8a916b04fa1
-389, 0xf12d2f0cb0a41cff
-390, 0x8102b5f91923cc2a
-391, 0x91d95fcb9cb1346d
-392, 0x819ccf0d122537ac
-393, 0x34646b1c3f9a8527
-394, 0x4a3a7df812ff79cb
-395, 0xc3d0b50ed434ad24
-396, 0x3e6cd372b453b5f0
-397, 0x39101f6226c43c8c
-398, 0xff41e5b6b7ff540c
-399, 0x1e8d77bc3f12e0f4
-400, 0x748d0860be568eee
-401, 0x5baac1f743bfeff3
-402, 0x8bdbd895b2eed2d8
-403, 0x5d3a01fa82bd88d4
-404, 0x577271d2de3e06f4
-405, 0xd4fccaeb0db61acb
-406, 0xa088377ed2b1d841
-407, 0x6f2e9e1566f37b5b
-408, 0xb8d85eef688c049a
-409, 0x6b7c06c55078761
-410, 0x223cd94cad1e0c32
-411, 0xbf27c193ae5881e3
-412, 0x5b784893a36d57dc
-413, 0xdc9fa53968c262dd
-414, 0xd7e820c76855fb61
-415, 0x72260eb94f096e2a
-416, 0x49144b5732ca1b94
-417, 0xba8d85a47582d428
-418, 0x558abe242dc84de2
-419, 0xc27b1d54557b9de5
-420, 0x80c1f06559385330
-421, 0x4a5c1d4252675c73
-422, 0x225e3a9f7b2da067
-423, 0x9ac95bac9d2234a1
-424, 0x696e500589e0e490
-425, 0xd0fe548d81c82185
-426, 0x68d8b783037b4743
-427, 0xbe1664f1a8d814f
-428, 0x2304308b691ca712
-429, 0x68e680af6b7189c5
-430, 0x13abe6c989949072
-431, 0x4c209f5029a59d0b
-432, 0x63361139df6fea7a
-433, 0xf07c52d8272cbdb
-434, 0x665023146f27fa7
-435, 0x7cb535c55ad7ad0e
-436, 0x76e366c7317eb1b0
-437, 0xa7d9b80b51585e9b
-438, 0x85f0bd60122198b9
-439, 0x34bc89d7e7827fd5
-440, 0xdfa1167988c85807
-441, 0xe78f45588bfdba02
-442, 0x172a023eba7357b2
-443, 0x7bc4c79e06ea755b
-444, 0x8aace6120b766b95
-445, 0x17b43a5a81b0db26
-446, 0xbc2b95819d959ff6
-447, 0x1b8841f2fe9c4622
-448, 0xc094a747ec30d67a
-449, 0xf5b93ec01484b937
-450, 0x659bbe8bdfd43f01
-451, 0x9d96c22bcf9c64c9
-452, 0xcf7df324fba052ec
-453, 0x5e4acd4f9e048e0b
-454, 0xe3a0e7e9869c5dd2
-455, 0x4eb444727e1c346e
-456, 0x7f6cda1ca7b3eb67
-457, 0x72fccac63ca649e9
-458, 0x711bfbf79a093651
-459, 0x5d48599fae7fd6a3
-460, 0xcc640119a296b34e
-461, 0x39acfb198b2b439
-462, 0xde759b50e2db66f9
-463, 0xe83bf8363827e06
-464, 0x484d50365017de87
-465, 0x4c3b5dbacd68394b
-466, 0xbbe47788c079218c
-467, 0xd44099290c25fe62
-468, 0x3b7d1bd6f91f3857
-469, 0xe7366a677d2b7eb3
-470, 0xfaa770590b197910
-471, 0x610b7a2fe8c4e80e
-472, 0x13451e1bf520a796
-473, 0x7e3d18c47e821077
-474, 0x8fd3a77c86eb9804
-475, 0xf24be740c87eadab
-476, 0xd5a52e6d0b58345
-477, 0xae386b5ca037a8d
-478, 0xb59fd16baf160f26
-479, 0xd4a05b473f6e0a8a
-480, 0x47ede6678c2c6420
-481, 0x8851ed397da6f850
-482, 0x1de775cdb392d89b
-483, 0x74e6c8ec9513ea38
-484, 0x30ae39e04187a984
-485, 0x614cfd09d043d601
-486, 0x3e0173138f562ee1
-487, 0x822d415a26bdba96
-488, 0x432f6dec77edd9a8
-489, 0x47a3a179627546b8
-490, 0x845dd7ffb1fe6d78
-491, 0x9778d5782de13a48
-492, 0x760198319b3cacce
-493, 0x420ee262d07dd7c
-494, 0x847c7424c365df20
-495, 0x56b3b590fb83ba16
-496, 0x7cd2410390a3e797
-497, 0xbb0c21b47aab8857
-498, 0x2743883e70a36a18
-499, 0xff8b29cdc75ebb7
-500, 0xe1e04a0f0379686f
-501, 0xcfdf3083b792f281
-502, 0x27392ca026b55e88
-503, 0xeeb195994fd56abb
-504, 0x7cf210041345882c
-505, 0x3ddca2b8951fea4e
-506, 0x21c89d88a3833996
-507, 0xe7128bccc4b25c9b
-508, 0xe39b0fb96a4c05ae
-509, 0xedf5326550594554
-510, 0x4aa45fe66b575558
-511, 0x2799fc8d3b06f777
-512, 0x2824863087187501
-513, 0xa15fa00818118906
-514, 0x559fc9e9344a310
-515, 0x1682745f8d571671
-516, 0x80b54f29f47a28d0
-517, 0x38e28103ffd9f771
-518, 0xedb5f440dab80945
-519, 0xdb0b8d04cece6091
-520, 0x1f60a7cae5ae8412
-521, 0x6719c0405e92b31d
-522, 0x56752def7d642302
-523, 0xa5b0900f93c352dd
-524, 0x5b82baf53be8983d
-525, 0x7726202ccee5cbb6
-526, 0x1641c84c7f87a765
-527, 0x835ae1a82be4265e
-528, 0x5f9ccee69c1d9da
-529, 0x3e2a2228e21039b7
-530, 0xa45873582866d005
-531, 0x7fbeffc99401e59e
-532, 0xcf66a6a974057890
-533, 0xd53704a96af96fd
-534, 0x1a8b5e3460704b64
-535, 0x6939b27bb32ba451
-536, 0x3c39293e637a0115
-537, 0x335a6e6b779b8c4e
-538, 0x75235d767dfd3d00
-539, 0xbdf0b36936b17c90
-540, 0x982dc5e4915a3a3a
-541, 0x74657ac256407f55
-542, 0x603a724457b796b6
-543, 0xf178694f7a3f98bd
-544, 0xe712de12db2aba47
-545, 0x1ca272d99a3355d8
-546, 0x93e7054d3e8dafc7
-547, 0xa29597810eff04c1
-548, 0xade242c0ae4bcea3
-549, 0xbcd226e2bd9d0e64
-550, 0x2e02e5736f889a
-551, 0x3622dc09f5fdd576
-552, 0x6e66bd2a10d78705
-553, 0x71d8f19110d5b4d0
-554, 0xacae934ab3d759f0
-555, 0x68d670d5f9272132
-556, 0x571fb09d082e7da7
-557, 0x154540c51b7d8b33
-558, 0x1e2f3710c0b6890
-559, 0xaf26a826ef444b30
-560, 0x9fc9fdbd9342be72
-561, 0x9b33b306d22a35e0
-562, 0xb6d5895f56d4197b
-563, 0x92fef06c1353b2e3
-564, 0x804e3eb42e65b938
-565, 0x73d5cd4bb7270902
-566, 0x274b8ac4925da8fd
-567, 0xa9a57999f5df2e2f
-568, 0xa6000be059e088b
-569, 0x57de4fc48c9e9e84
-570, 0x16727392e94ee9bf
-571, 0x53c9032f62848c4d
-572, 0x8a8ddd8fcf0676dd
-573, 0x1436de7c1735087
-574, 0xfa93b7d1425e8667
-575, 0xec34ca5f3f84bb2f
-576, 0x489ed44d0880c4c8
-577, 0xb3b6051de7a6f740
-578, 0x2f303cb0f4040f11
-579, 0x302c42a6adbcbcb2
-580, 0x28ed7b87695cd600
-581, 0xee78d3b782a2fcd0
-582, 0xc47a2441a1082032
-583, 0xec9965704a044f33
-584, 0xcb1563e968460dc
-585, 0xfecbb4fa2b544f93
-586, 0x3f3d7437a6d29a3d
-587, 0xe4bfaccd729414ca
-588, 0xb741ed954572d172
-589, 0xf34b49bf10ae47b6
-590, 0x1fbd1f068f1b796d
-591, 0xc1d556e64345b226
-592, 0x85bbfa50a899c7be
-593, 0x5310045dcf0fea8
-594, 0xbc6f6fb7f00e5960
-595, 0xf8bdf4074f2b5f5e
-596, 0x2a5817aa122dc97f
-597, 0x6d5ef86d6b8ad0ce
-598, 0x96e7ccc235abb79e
-599, 0x8d531c4cea492f66
-600, 0xfc124a123b4ce02a
-601, 0xc6087ffd9130c2ca
-602, 0x3a724c46f0f06175
-603, 0x59980713cfe4fe92
-604, 0xecde418e64a11bd
-605, 0x5c9b333a0f0337cc
-606, 0xcf014d508fc8e83a
-607, 0x83998bb2aa4e16ba
-608, 0xde8f5167ac0a40d9
-609, 0xe93b1846914c0dc7
-610, 0x668831ca8fd50c25
-611, 0xec764b87e402c28e
-612, 0xd0e1303e56f6b268
-613, 0xa6b9f3c4872dbcd5
-614, 0x12a89c116ad924f0
-615, 0x23857c375ae928c8
-616, 0x29b117f63f2e8c1b
-617, 0x64ff6cce272aa46d
-618, 0xd40fb15b38d59f70
-619, 0x6e5a6257c4cc0c66
-620, 0x7b54845e6e119a4e
-621, 0x9d88bf3dd9fa0f0e
-622, 0xb6687fd4980a5d43
-623, 0x4f2e3fef88b640b8
-624, 0xf07ac2f7e2df40fa
-625, 0x24059bd0ecb6c6a9
-626, 0x6204a47cbd57453d
-627, 0x8477fd1a13ea9678
-628, 0x4555083f5eada49f
-629, 0x352443e5d984691c
-630, 0x3e904f796a9c5ffa
-631, 0x11e182bc43754609
-632, 0x608cdbe03699a5d4
-633, 0x2619146efbf59f0
-634, 0x9b852370063940ee
-635, 0xa1d8e7e91e42a52b
-636, 0x19179affce38fa3c
-637, 0xf68ff1ccce70380c
-638, 0x12103cb41741ab38
-639, 0xdca7902fa6d960b2
-640, 0xad46a2fc70025445
-641, 0xac92f0b2d150d716
-642, 0x5de115babb43326e
-643, 0xf335366fd69e4bcd
-644, 0xe9aecd1f88889cd
-645, 0xbce60087987b51d1
-646, 0xcfd395a167103939
-647, 0x2fdcb12826ac806c
-648, 0xbd5129970869ccd6
-649, 0x5e922b68030c2698
-650, 0x7ada02a56d17779a
-651, 0x7a1254c652b99ccc
-652, 0x8be78733623db772
-653, 0xc22439789b68f0a8
-654, 0xee51ad4ab1a9a6ed
-655, 0x44b15fa27694d9be
-656, 0xc5b93e6c57805153
-657, 0xcf03df495c283a89
-658, 0x5c2a41954bb44bb
-659, 0x9e651cb8c650dd
-660, 0x73a20ee82570d4a8
-661, 0x5f805cab085e971f
-662, 0x5354410872a8f587
-663, 0x1b50ef4e9519338d
-664, 0xdeb873412301a1ce
-665, 0x3a286bb2f5f8db39
-666, 0xad117a0d4dc7f82e
-667, 0xdd880d581169d989
-668, 0x8356be106382a704
-669, 0x7c684ad93e996ff3
-670, 0x6b2d09e61ac02c11
-671, 0x99ad8c074fe046dc
-672, 0x4a9b4f0e7c4ffa24
-673, 0x38afdcb5893b466
-674, 0x7ad58ef97c3d35c
-675, 0xdd7c17c0d67ab69
-676, 0x61c77caf27938c86
-677, 0x978fc491080c0cee
-678, 0x4c1750f8684c1ca4
-679, 0x86b4c683d5fe657e
-680, 0x720e2bd8ec76cffc
-681, 0x73ca52b4a7dd3b85
-682, 0xeb10a691e12ea3ca
-683, 0x90355e369297b259
-684, 0x6c6bc16f639678ca
-685, 0xd989f4c724f8fba7
-686, 0xbb1ba7e2ca1c4391
-687, 0x81e4194500a0d267
-688, 0xbb25489c1dcbf93f
-689, 0x74d26b75e9f57fd
-690, 0x59c085fa99b6493d
-691, 0x3359805b0fc3fef9
-692, 0x60ef0f3a85e60650
-693, 0xf1a3692c8591e8d6
-694, 0xd7c8d2e7f3d3546e
-695, 0xe8fc8518c11ca881
-696, 0x3380ef12114d1818
-697, 0x87203c98ff21fcaf
-698, 0xbc37f8e034002ef8
-699, 0x891b7c3f55d02300
-700, 0x814eec8ff8956f0a
-701, 0xa370639852acceae
-702, 0x6c566310b6b00f15
-703, 0xd69fe78b9c8a05a6
-704, 0xb7b0df518738419e
-705, 0x2a0c1185b29ed965
-706, 0x636c841214c0a8cf
-707, 0xbf56297859e9bb72
-708, 0x2b5b9d432d6d008f
-709, 0x1ea586cf0f86f542
-710, 0x23a2a1af76cbc988
-711, 0x6c72c799b6ed93f3
-712, 0x2266785315f3bb13
-713, 0xb68cd6e87b94065a
-714, 0x5d395704514bb808
-715, 0x334bde59d526ee4
-716, 0xc5a6d87f96f055fa
-717, 0xd47001378b4dcf08
-718, 0x7305818a39057557
-719, 0x8f72c128eac6d32
-720, 0x4957ed799339bbdc
-721, 0xeb47d505f61dd5fa
-722, 0x8ce8817cd6acc93a
-723, 0x84ef66e511a52f35
-724, 0xbf5aa34bbaef7e1f
-725, 0xadaa5ba2a5ee660e
-726, 0x6eec8ac924058eea
-727, 0x8af63be4d1a1b202
-728, 0x88eccf85fd9fce32
-729, 0xf19a1122f394af05
-730, 0x8dcd15d1c14f5077
-731, 0x6c0f2e6135e36545
-732, 0xe58f89bec4d929c8
-733, 0x4eea88221d983ef9
-734, 0x51ae3956d53e1a80
-735, 0x40d8a172bf713bb6
-736, 0x3e33536e43ad4fa2
-737, 0xeff9938a179138fa
-738, 0x3e372bff1f51df8b
-739, 0x59b86a407817c86c
-740, 0x947164c2c57f9bd8
-741, 0xd8e67bb799d84475
-742, 0x4d9ed254d8189595
-743, 0xa021d8d181328996
-744, 0xc703e402f8e4688b
-745, 0xd1eb104c970dd5fe
-746, 0xd5bf4683b9337f8e
-747, 0x98f405a2d998f06
-748, 0x59c734ddd208e85c
-749, 0xbd167be2d43fde24
-750, 0x70602daab163fbe2
-751, 0xeb2f2b37cbfe13e7
-752, 0x28baa8f3fc4c4666
-753, 0xe212ffe352ea5ce6
-754, 0x538b93d2285eda3a
-755, 0x3a9482ac69a39e1b
-756, 0x3a98983ed4367767
-757, 0x1dc851c69e35d601
-758, 0xac7f83e4b02e9bb8
-759, 0xa939f99c5615ef7b
-760, 0x439437f129076339
-761, 0x79a251bb1d50ce25
-762, 0xaa7b6ff8f13a7424
-763, 0x1b244bd86404327b
-764, 0xc84d99185ab2a7d6
-765, 0xf6dcde975493c40b
-766, 0xdee46f4346cf6af
-767, 0x739b75df1fe18712
-768, 0x3d05cb298311f3e9
-769, 0x1fba9d9c10dc7780
-770, 0x31637fc416267053
-771, 0x46694e36246b8be2
-772, 0x8c67095ae6eaf1e4
-773, 0xebe2a68c27963dca
-774, 0x532d344b14306cf2
-775, 0x6a847c8f3ae2ac92
-776, 0x8034bcb5a50cbd6a
-777, 0x7544766784261059
-778, 0xe641799652df63ca
-779, 0xd8cacad7099c07de
-780, 0x429e62da116e4876
-781, 0x4442c8b57a5b7ef5
-782, 0xa7ea9c348cbeebaa
-783, 0xce1a34f57bb2a7fa
-784, 0xbb29ef457c9509cc
-785, 0x1ba1030b19a32c1c
-786, 0x412d1eb07cee79b8
-787, 0x3627dd37c6b36848
-788, 0x45432b319f26a2a9
-789, 0xb9a12e188cee2a29
-790, 0xeee69e0f1b1efd66
-791, 0xd4ccd61bc3fb8837
-792, 0x1b600476917cbf62
-793, 0x522950ddce26c142
-794, 0x956d8a5dbe9aa431
-795, 0x31cfba73bb524b7d
-796, 0xc3b709a56885a6ac
-797, 0x7341d4e32fffcdf8
-798, 0x5ed87c5315e4775
-799, 0x60fa512183e3dad5
-800, 0x4df6df14e9c2935f
-801, 0xdec2dc983ab42a9
-802, 0x28265e213fd6de41
-803, 0x2f85d825454add06
-804, 0xf18119191ac41aa
-805, 0xf870e36e83f4face
-806, 0x2a4b213d973d83c8
-807, 0x2c7094cde18ba8ec
-808, 0xb5998e0a1914446b
-809, 0xefcb960ff010503a
-810, 0xa8d928b99104aef5
-811, 0xe7a6893116e383a8
-812, 0x552dbe180a51b6c9
-813, 0x16b73f3832c9990c
-814, 0xfefee9504783e187
-815, 0xc12d3aa0c1f8608b
-816, 0xd5232106c7adea7e
-817, 0xb207e82667fb71ed
-818, 0xe93c50ef54a791cf
-819, 0x3099900fdf7b1750
-820, 0xaa2a46c352132ad0
-821, 0xf2414daa174335e4
-822, 0x33080f98c42bbad2
-823, 0x9df24fe0b5b13394
-824, 0x840eedf2eec5fdb6
-825, 0x3715e262efbc907d
-826, 0xa70a8cccfbe8a11f
-827, 0x4a57a6f16ea4c9f3
-828, 0xe03dbe2f1493e9e1
-829, 0xbd92759a7becd4e4
-830, 0x21a3d87c3766887e
-831, 0x6414f570caa74ef1
-832, 0x4e27490fc3fc0234
-833, 0xd4c40310c6ab2eba
-834, 0xfbe8acd168ffd62d
-835, 0x30b19992f1975ac8
-836, 0xaf93d22a8561f631
-837, 0x4574ebab81bed3b1
-838, 0x5390c6026e3940c7
-839, 0x7a5154d076a8b504
-840, 0x9676f2495f742943
-841, 0x8cfdb9e11bdb4502
-842, 0x36af5c8754d9ca17
-843, 0x61477e76367296ee
-844, 0xd6f5f40f66acc700
-845, 0xe62c2462e96af1b8
-846, 0x18029746ac09ef3e
-847, 0x871bbe15da7e0176
-848, 0x2443e806f54d179
-849, 0x9103af1634f9d0ac
-850, 0xe6e5358eaa0efa2b
-851, 0xdff4859198244a67
-852, 0x6e48c357be6042b
-853, 0x6bb9e8aeb24d656a
-854, 0x1b89fbb05f8438cb
-855, 0xe0cea835b4db045d
-856, 0x4eafe5c195e29d47
-857, 0xd2f0a452be9163f0
-858, 0xa7ae1d0eee928fe6
-859, 0x42c7a26c82a062c4
-860, 0xa8e93bcd89c5704e
-861, 0x73784be379f09c34
-862, 0x91f8e599342d013f
-863, 0x79c20bc462215ccc
-864, 0x6ee77bc91b3753a6
-865, 0xd2c116d1eb2650d0
-866, 0x388f9767cfe30ebe
-867, 0xdde5d5966815e7ae
-868, 0x459b838c87ca1dec
-869, 0xdf96cdb2bc916a60
-870, 0x215c4195b935d5ca
-871, 0x56c9f516528598e5
-872, 0x1d8492a9923640f3
-873, 0x97830ac45234686f
-874, 0x67f75117a7c952bb
-875, 0xf1939dc69391e65d
-876, 0xfc44bb1162cb2868
-877, 0x92b33d9df8fc6925
-878, 0x6c4496920de0d558
-879, 0xa4616bb101e924aa
-880, 0xa0afc9701ad83cdb
-881, 0x62d555323b0494d2
-882, 0xf18b31447a2dfdc3
-883, 0xb2ece318c128d4f3
-884, 0x29efea45a76b9b8f
-885, 0xae05362b365d9cd2
-886, 0x5c4d374ce6aefb44
-887, 0xb9cdc65eec94136e
-888, 0xf0212f42e3d4f5dc
-889, 0xcde7c5085f95d8d8
-890, 0x9cc3799673a644e8
-891, 0xf878d89199bead01
-892, 0xab684fb9666abf61
-893, 0x3070d399b7a07d3d
-894, 0x6d8c51673eeeef73
-895, 0x9bf4062ff5471832
-896, 0x92774cd03c511d00
-897, 0xc1aad7c6980df547
-898, 0x3291e3a234d50cc0
-899, 0x75645079bbe9d34a
-900, 0x7f28bab9eba28fae
-901, 0xa84415684ed6d765
-902, 0x56d9d67653cd172
-903, 0xa7bfed939db93e91
-904, 0x92940e5162d50470
-905, 0xcd6bf601e08f07a9
-906, 0x2ea9104d785e35cb
-907, 0xd771ddd541649214
-908, 0x352554afbf9258d
-909, 0x9d855486b77c5bc3
-910, 0xdb03cd71e906e1df
-911, 0x7c2621690aabc265
-912, 0x1dd4ac7369a04640
-913, 0x57796cbc93d4d854
-914, 0x42a373d152eca785
-915, 0xbe7389edb8b144d3
-916, 0x8b6245bf01d2e4df
-917, 0xacd1f9fcca317652
-918, 0x84545ac79a3eb960
-919, 0x2d2f28e6a8459db3
-920, 0x42b3a2e26ddeccdd
-921, 0xe858272777abcef6
-922, 0xd9b5be7340dec08d
-923, 0xe991af3579ac4fb6
-924, 0x7c30699b349fa6c1
-925, 0xbb842be14f7b5b9a
-926, 0x1d31e1ca791a1cf0
-927, 0xf2bd448ebb878bc0
-928, 0x26a6adf6709863cb
-929, 0xb11aa978539e3a34
-930, 0xce554a11bbbedd1d
-931, 0x553d3c012682a47b
-932, 0xb3c90ed36715903
-933, 0xda3c5c706e39e395
-934, 0x4e7f66006d583c2a
-935, 0x6424190e9d28ca3a
-936, 0x9916685e7384f3bf
-937, 0x1285e17347eb806d
-938, 0x877f10baf13e6659
-939, 0x222700ed5086438d
-940, 0xd2473d08396634b8
-941, 0xb6b68f3bc883a77d
-942, 0x168a489b0b7f5f63
-943, 0xee34dcf1f93ad3fa
-944, 0xd25ef824f614f65a
-945, 0xe30981905354f477
-946, 0x9463ef623c5eb3f8
-947, 0x46657408ea66980d
-948, 0xa2e58d51d6e8e7f9
-949, 0xd80d7df3007e9845
-950, 0xd90fa96f4fc0f7aa
-951, 0xd2a6059d171bbb33
-952, 0xb8bacb8f11c65c2d
-953, 0x401de84b6a8b1ac
-954, 0xf8b6eed644c802d9
-955, 0x30c927749fdd8e6
-956, 0x17c2f4f9c4524e16
-957, 0xa9c677daae4acc7e
-958, 0x82c78d9c6b10446f
-959, 0x5e544188277da629
-960, 0x7c6e1bd3b861dcd7
-961, 0xd4b00871a7f67d0d
-962, 0x6b66ee142821e6d5
-963, 0x176d5e39f3b22474
-964, 0x58ea746f62acf933
-965, 0xc61fabd9961c3a51
-966, 0xb27ce0f87b416e3d
-967, 0xd3c82b525b000e70
-968, 0x99578704fb3ff4e4
-969, 0x747da52468875493
-970, 0x5c5bfab7a474465b
-971, 0xd82276bdb30e3dbd
-972, 0x1d758772eebffe2
-973, 0xfed9d1e3ca887a6e
-974, 0x23dd5f7b3ff9472b
-975, 0xae2e842b51c9c598
-976, 0xe851bc45531123d7
-977, 0x1a18d2777151c29
-978, 0x9e82f3be14b12a48
-979, 0xdf9fdb3abc3e72cf
-980, 0xdbea56e918ccb176
-981, 0x47abbd896eb0ca1a
-982, 0xe850ee3cef9334dd
-983, 0x3d69fe95275e7f2e
-984, 0x4fcb936c048d8812
-985, 0xc98f0f6bb9865a99
-986, 0xc951cdb73514709
-987, 0x3ca839c27ca26de9
-988, 0x1478848a311f9cc5
-989, 0x35d2244064967478
-990, 0xe71df2d9732ffdc0
-991, 0xa12417d7b7b9e0ce
-992, 0xa1bb6da3f284f77c
-993, 0xf551e1c3171575eb
-994, 0x16083ac8a062747d
-995, 0x866d6c3a630fd4da
-996, 0x8a972ff46b3c5c4c
-997, 0x70af3b475e4a3d5d
-998, 0x2c143fd5c01d9cf5
-999, 0x68089ffadc8ea2b9
diff --git a/numpy/random/tests/data/xoshiro256starstar-testset-1.csv b/numpy/random/tests/data/xoshiro256-testset-1.csv
index 534799b04..534799b04 100644
--- a/numpy/random/tests/data/xoshiro256starstar-testset-1.csv
+++ b/numpy/random/tests/data/xoshiro256-testset-1.csv
diff --git a/numpy/random/tests/data/xoshiro256starstar-testset-2.csv b/numpy/random/tests/data/xoshiro256-testset-2.csv
index b688fcb2a..b688fcb2a 100644
--- a/numpy/random/tests/data/xoshiro256starstar-testset-2.csv
+++ b/numpy/random/tests/data/xoshiro256-testset-2.csv
diff --git a/numpy/random/tests/data/xoshiro512starstar-testset-1.csv b/numpy/random/tests/data/xoshiro512-testset-1.csv
index 78fb903ee..78fb903ee 100644
--- a/numpy/random/tests/data/xoshiro512starstar-testset-1.csv
+++ b/numpy/random/tests/data/xoshiro512-testset-1.csv
diff --git a/numpy/random/tests/data/xoshiro512starstar-testset-2.csv b/numpy/random/tests/data/xoshiro512-testset-2.csv
index 264308f1a..264308f1a 100644
--- a/numpy/random/tests/data/xoshiro512starstar-testset-2.csv
+++ b/numpy/random/tests/data/xoshiro512-testset-2.csv
diff --git a/numpy/random/tests/test_against_numpy.py b/numpy/random/tests/test_against_numpy.py
index 3c83932e8..a000e5db7 100644
--- a/numpy/random/tests/test_against_numpy.py
+++ b/numpy/random/tests/test_against_numpy.py
@@ -5,7 +5,7 @@ from numpy.testing import (assert_allclose, assert_array_equal, assert_equal,
import pytest
-from numpy.random import RandomGenerator, MT19937, generator
+from numpy.random import Generator, MT19937, generator
from numpy.random import RandomState
@@ -93,17 +93,17 @@ class TestAgainstNumPy(object):
@classmethod
def setup_class(cls):
cls.np = numpy.random
- cls.brng = MT19937
+ cls.bit_generator = MT19937
cls.seed = [2 ** 21 + 2 ** 16 + 2 ** 5 + 1]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.rs = RandomState(cls.brng(*cls.seed))
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.rs = RandomState(cls.bit_generator(*cls.seed))
cls.nprs = cls.np.RandomState(*cls.seed)
- cls.initial_state = cls.rg.brng.state
+ cls.initial_state = cls.rg.bit_generator.state
cls._set_common_state()
@classmethod
def _set_common_state(cls):
- state = cls.rg.brng.state
+ state = cls.rg.bit_generator.state
st = [[]] * 5
st[0] = 'MT19937'
st[1] = state['state']['key']
@@ -125,7 +125,7 @@ class TestAgainstNumPy(object):
def _is_state_common(self):
state = self.nprs.get_state()
- state2 = self.rg.brng.state
+ state2 = self.rg.bit_generator.state
assert (state[1] == state2['state']['key']).all()
assert (state[2] == state2['state']['pos'])
@@ -138,10 +138,10 @@ class TestAgainstNumPy(object):
assert_allclose(state[4], state2['gauss'], atol=1e-10)
def test_common_seed(self):
- self.rg.brng.seed(1234)
+ self.rg.bit_generator.seed(1234)
self.nprs.seed(1234)
self._is_state_common()
- self.rg.brng.seed(23456)
+ self.rg.bit_generator.seed(23456)
self.nprs.seed(23456)
self._is_state_common()
@@ -149,8 +149,8 @@ class TestAgainstNumPy(object):
nprs = np.random.RandomState()
nprs.standard_normal(99)
state = nprs.get_state()
- self.rg.brng.state = state
- state2 = self.rg.brng.state
+ self.rg.bit_generator.state = state
+ state2 = self.rg.bit_generator.state
assert (state[1] == state2['state']['key']).all()
assert (state[2] == state2['state']['pos'])
@@ -158,7 +158,7 @@ class TestAgainstNumPy(object):
self._set_common_state()
self._is_state_common()
v1 = self.nprs.random_sample(10)
- v2 = self.rg.random_sample(10)
+ v2 = self.rg.random(10)
assert_array_equal(v1, v2)
@@ -263,16 +263,6 @@ class TestAgainstNumPy(object):
self.rg.vonmises)
self._is_state_common()
- def test_random_integers(self):
- self._set_common_state()
- self._is_state_common()
- with suppress_warnings() as sup:
- sup.record(DeprecationWarning)
- compare_2_input(self.nprs.random_integers,
- self.rg.random_integers,
- is_scalar=True)
- self._is_state_common()
-
def test_binomial(self):
self._set_common_state()
self._is_state_common()
@@ -281,14 +271,6 @@ class TestAgainstNumPy(object):
is_np=True)
self._is_state_common()
- def test_rand(self):
- self._set_common_state()
- self._is_state_common()
- f = self.rg.rand
- g = self.nprs.rand
- assert_allclose(f(10), g(10))
- assert_allclose(f(3, 4, 5), g(3, 4, 5))
-
def test_poisson_lam_max(self):
assert_allclose(self.rg.poisson_lam_max, self.nprs.poisson_lam_max)
@@ -367,40 +349,40 @@ class TestAgainstNumPy(object):
def test_randint(self):
self._set_common_state()
self._is_state_common()
- compare_2_input(self.rg.randint,
+ compare_2_input(self.rg.integers,
self.nprs.randint,
is_scalar=True)
self._is_state_common()
def test_scalar(self):
- s = RandomGenerator(MT19937(0))
- assert_equal(s.randint(1000), 684)
+ s = Generator(MT19937(0))
+ assert_equal(s.integers(1000), 684)
s1 = np.random.RandomState(0)
assert_equal(s1.randint(1000), 684)
- assert_equal(s1.randint(1000), s.randint(1000))
+ assert_equal(s1.randint(1000), s.integers(1000))
- s = RandomGenerator(MT19937(4294967295))
- assert_equal(s.randint(1000), 419)
+ s = Generator(MT19937(4294967295))
+ assert_equal(s.integers(1000), 419)
s1 = np.random.RandomState(4294967295)
assert_equal(s1.randint(1000), 419)
- assert_equal(s1.randint(1000), s.randint(1000))
+ assert_equal(s1.randint(1000), s.integers(1000))
- self.rg.brng.seed(4294967295)
+ self.rg.bit_generator.seed(4294967295)
self.nprs.seed(4294967295)
self._is_state_common()
def test_array(self):
- s = RandomGenerator(MT19937(range(10)))
- assert_equal(s.randint(1000), 468)
+ s = Generator(MT19937(range(10)))
+ assert_equal(s.integers(1000), 468)
s = np.random.RandomState(range(10))
assert_equal(s.randint(1000), 468)
- s = RandomGenerator(MT19937(np.arange(10)))
- assert_equal(s.randint(1000), 468)
- s = RandomGenerator(MT19937([0]))
- assert_equal(s.randint(1000), 973)
- s = RandomGenerator(MT19937([4294967295]))
- assert_equal(s.randint(1000), 265)
+ s = Generator(MT19937(np.arange(10)))
+ assert_equal(s.integers(1000), 468)
+ s = Generator(MT19937([0]))
+ assert_equal(s.integers(1000), 973)
+ s = Generator(MT19937([4294967295]))
+ assert_equal(s.integers(1000), 265)
# Tests using legacy generator
def test_chisquare(self):
diff --git a/numpy/random/tests/test_direct.py b/numpy/random/tests/test_direct.py
index fd2d7eb9a..4a95dfca6 100644
--- a/numpy/random/tests/test_direct.py
+++ b/numpy/random/tests/test_direct.py
@@ -7,9 +7,9 @@ from numpy.testing import assert_equal, assert_allclose, assert_array_equal, \
assert_raises
import pytest
-from numpy.random import RandomGenerator, MT19937, DSFMT, ThreeFry32, ThreeFry, \
- PCG32, PCG64, Philox, Xoroshiro128, Xorshift1024, Xoshiro256StarStar, \
- Xoshiro512StarStar, RandomState
+from numpy.random import Generator, MT19937, DSFMT, ThreeFry32, ThreeFry, \
+ Philox, Xoroshiro128, Xorshift1024, Xoshiro256, \
+ Xoshiro512, RandomState
from numpy.random.common import interface
try:
@@ -129,7 +129,7 @@ class Base(object):
@classmethod
def setup_class(cls):
- cls.brng = Xoroshiro128
+ cls.bit_generator = Xoroshiro128
cls.bits = 64
cls.dtype = np.uint64
cls.seed_error_type = TypeError
@@ -148,177 +148,173 @@ class Base(object):
return {'seed': seed, 'data': np.array(data, dtype=cls.dtype)}
def test_raw(self):
- brng = self.brng(*self.data1['seed'])
- uints = brng.random_raw(1000)
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ uints = bit_generator.random_raw(1000)
assert_equal(uints, self.data1['data'])
- brng = self.brng(*self.data1['seed'])
- uints = brng.random_raw()
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ uints = bit_generator.random_raw()
assert_equal(uints, self.data1['data'][0])
- brng = self.brng(*self.data2['seed'])
- uints = brng.random_raw(1000)
+ bit_generator = self.bit_generator(*self.data2['seed'])
+ uints = bit_generator.random_raw(1000)
assert_equal(uints, self.data2['data'])
def test_random_raw(self):
- brng = self.brng(*self.data1['seed'])
- uints = brng.random_raw(output=False)
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ uints = bit_generator.random_raw(output=False)
assert uints is None
- uints = brng.random_raw(1000, output=False)
+ uints = bit_generator.random_raw(1000, output=False)
assert uints is None
def test_gauss_inv(self):
n = 25
- rs = RandomState(self.brng(*self.data1['seed']))
+ rs = RandomState(self.bit_generator(*self.data1['seed']))
gauss = rs.standard_normal(n)
assert_allclose(gauss,
gauss_from_uint(self.data1['data'], n, self.bits))
- rs = RandomState(self.brng(*self.data2['seed']))
+ rs = RandomState(self.bit_generator(*self.data2['seed']))
gauss = rs.standard_normal(25)
assert_allclose(gauss,
gauss_from_uint(self.data2['data'], n, self.bits))
def test_uniform_double(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
+ rs = Generator(self.bit_generator(*self.data1['seed']))
vals = uniform_from_uint(self.data1['data'], self.bits)
- uniforms = rs.random_sample(len(vals))
+ uniforms = rs.random(len(vals))
assert_allclose(uniforms, vals)
assert_equal(uniforms.dtype, np.float64)
- rs = RandomGenerator(self.brng(*self.data2['seed']))
+ rs = Generator(self.bit_generator(*self.data2['seed']))
vals = uniform_from_uint(self.data2['data'], self.bits)
- uniforms = rs.random_sample(len(vals))
+ uniforms = rs.random(len(vals))
assert_allclose(uniforms, vals)
assert_equal(uniforms.dtype, np.float64)
def test_uniform_float(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
+ rs = Generator(self.bit_generator(*self.data1['seed']))
vals = uniform32_from_uint(self.data1['data'], self.bits)
- uniforms = rs.random_sample(len(vals), dtype=np.float32)
+ uniforms = rs.random(len(vals), dtype=np.float32)
assert_allclose(uniforms, vals)
assert_equal(uniforms.dtype, np.float32)
- rs = RandomGenerator(self.brng(*self.data2['seed']))
+ rs = Generator(self.bit_generator(*self.data2['seed']))
vals = uniform32_from_uint(self.data2['data'], self.bits)
- uniforms = rs.random_sample(len(vals), dtype=np.float32)
+ uniforms = rs.random(len(vals), dtype=np.float32)
assert_allclose(uniforms, vals)
assert_equal(uniforms.dtype, np.float32)
def test_seed_float(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(self.seed_error_type, rs.brng.seed, np.pi)
- assert_raises(self.seed_error_type, rs.brng.seed, -np.pi)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(self.seed_error_type, rs.bit_generator.seed, np.pi)
+ assert_raises(self.seed_error_type, rs.bit_generator.seed, -np.pi)
def test_seed_float_array(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(self.seed_error_type, rs.brng.seed, np.array([np.pi]))
- assert_raises(self.seed_error_type, rs.brng.seed, np.array([-np.pi]))
- assert_raises(ValueError, rs.brng.seed, np.array([np.pi, -np.pi]))
- assert_raises(TypeError, rs.brng.seed, np.array([0, np.pi]))
- assert_raises(TypeError, rs.brng.seed, [np.pi])
- assert_raises(TypeError, rs.brng.seed, [0, np.pi])
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(self.seed_error_type, rs.bit_generator.seed, np.array([np.pi]))
+ assert_raises(self.seed_error_type, rs.bit_generator.seed, np.array([-np.pi]))
+ assert_raises(ValueError, rs.bit_generator.seed, np.array([np.pi, -np.pi]))
+ assert_raises(TypeError, rs.bit_generator.seed, np.array([0, np.pi]))
+ assert_raises(TypeError, rs.bit_generator.seed, [np.pi])
+ assert_raises(TypeError, rs.bit_generator.seed, [0, np.pi])
def test_seed_out_of_range(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(ValueError, rs.brng.seed, 2 ** (2 * self.bits + 1))
- assert_raises(ValueError, rs.brng.seed, -1)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(ValueError, rs.bit_generator.seed, 2 ** (2 * self.bits + 1))
+ assert_raises(ValueError, rs.bit_generator.seed, -1)
def test_seed_out_of_range_array(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(ValueError, rs.brng.seed, [2 ** (2 * self.bits + 1)])
- assert_raises(ValueError, rs.brng.seed, [-1])
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(ValueError, rs.bit_generator.seed, [2 ** (2 * self.bits + 1)])
+ assert_raises(ValueError, rs.bit_generator.seed, [-1])
def test_repr(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert 'RandomGenerator' in repr(rs)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert 'Generator' in repr(rs)
assert '{:#x}'.format(id(rs)).upper().replace('X', 'x') in repr(rs)
def test_str(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert 'RandomGenerator' in str(rs)
- assert str(self.brng.__name__) in str(rs)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert 'Generator' in str(rs)
+ assert str(self.bit_generator.__name__) in str(rs)
assert '{:#x}'.format(id(rs)).upper().replace('X', 'x') not in str(rs)
- def test_generator(self):
- brng = self.brng(*self.data1['seed'])
- assert isinstance(brng.generator, RandomGenerator)
-
def test_pickle(self):
import pickle
- brng = self.brng(*self.data1['seed'])
- state = brng.state
- brng_pkl = pickle.dumps(brng)
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ state = bit_generator.state
+ brng_pkl = pickle.dumps(bit_generator)
reloaded = pickle.loads(brng_pkl)
reloaded_state = reloaded.state
- assert_array_equal(brng.generator.standard_normal(1000),
- reloaded.generator.standard_normal(1000))
- assert brng is not reloaded
+ assert_array_equal(Generator(bit_generator).standard_normal(1000),
+ Generator(reloaded).standard_normal(1000))
+ assert bit_generator is not reloaded
assert_state_equal(reloaded_state, state)
def test_invalid_state_type(self):
- brng = self.brng(*self.data1['seed'])
+ bit_generator = self.bit_generator(*self.data1['seed'])
with pytest.raises(TypeError):
- brng.state = {'1'}
+ bit_generator.state = {'1'}
def test_invalid_state_value(self):
- brng = self.brng(*self.data1['seed'])
- state = brng.state
- state['brng'] = 'otherBRNG'
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ state = bit_generator.state
+ state['bit_generator'] = 'otherBRNG'
with pytest.raises(ValueError):
- brng.state = state
+ bit_generator.state = state
def test_invalid_seed_type(self):
- brng = self.brng(*self.data1['seed'])
+ bit_generator = self.bit_generator(*self.data1['seed'])
for st in self.invalid_seed_types:
with pytest.raises(TypeError):
- brng.seed(*st)
+ bit_generator.seed(*st)
def test_invalid_seed_values(self):
- brng = self.brng(*self.data1['seed'])
+ bit_generator = self.bit_generator(*self.data1['seed'])
for st in self.invalid_seed_values:
with pytest.raises(ValueError):
- brng.seed(*st)
+ bit_generator.seed(*st)
def test_benchmark(self):
- brng = self.brng(*self.data1['seed'])
- brng._benchmark(1)
- brng._benchmark(1, 'double')
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ bit_generator._benchmark(1)
+ bit_generator._benchmark(1, 'double')
with pytest.raises(ValueError):
- brng._benchmark(1, 'int32')
+ bit_generator._benchmark(1, 'int32')
@pytest.mark.skipif(MISSING_CFFI, reason='cffi not available')
def test_cffi(self):
- brng = self.brng(*self.data1['seed'])
- cffi_interface = brng.cffi
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ cffi_interface = bit_generator.cffi
assert isinstance(cffi_interface, interface)
- other_cffi_interface = brng.cffi
+ other_cffi_interface = bit_generator.cffi
assert other_cffi_interface is cffi_interface
@pytest.mark.skipif(MISSING_CTYPES, reason='ctypes not available')
def test_ctypes(self):
- brng = self.brng(*self.data1['seed'])
- ctypes_interface = brng.ctypes
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ ctypes_interface = bit_generator.ctypes
assert isinstance(ctypes_interface, interface)
- other_ctypes_interface = brng.ctypes
+ other_ctypes_interface = bit_generator.ctypes
assert other_ctypes_interface is ctypes_interface
def test_getstate(self):
- brng = self.brng(*self.data1['seed'])
- state = brng.state
- alt_state = brng.__getstate__()
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ state = bit_generator.state
+ alt_state = bit_generator.__getstate__()
assert_state_equal(state, alt_state)
class TestXoroshiro128(Base):
@classmethod
def setup_class(cls):
- cls.brng = Xoroshiro128
+ cls.bit_generator = Xoroshiro128
cls.bits = 64
cls.dtype = np.uint64
cls.data1 = cls._read_csv(
@@ -330,31 +326,31 @@ class TestXoroshiro128(Base):
cls.invalid_seed_values = [(-2,), (np.empty((2, 2), dtype=np.int64),)]
-class TestXoshiro256StarStar(Base):
+class TestXoshiro256(Base):
@classmethod
def setup_class(cls):
- cls.brng = Xoshiro256StarStar
+ cls.bit_generator = Xoshiro256
cls.bits = 64
cls.dtype = np.uint64
cls.data1 = cls._read_csv(
- join(pwd, './data/xoshiro256starstar-testset-1.csv'))
+ join(pwd, './data/xoshiro256-testset-1.csv'))
cls.data2 = cls._read_csv(
- join(pwd, './data/xoshiro256starstar-testset-2.csv'))
+ join(pwd, './data/xoshiro256-testset-2.csv'))
cls.seed_error_type = TypeError
cls.invalid_seed_types = [('apple',), (2 + 3j,), (3.1,)]
cls.invalid_seed_values = [(-2,), (np.empty((2, 2), dtype=np.int64),)]
-class TestXoshiro512StarStar(Base):
+class TestXoshiro512(Base):
@classmethod
def setup_class(cls):
- cls.brng = Xoshiro512StarStar
+ cls.bit_generator = Xoshiro512
cls.bits = 64
cls.dtype = np.uint64
cls.data1 = cls._read_csv(
- join(pwd, './data/xoshiro512starstar-testset-1.csv'))
+ join(pwd, './data/xoshiro512-testset-1.csv'))
cls.data2 = cls._read_csv(
- join(pwd, './data/xoshiro512starstar-testset-2.csv'))
+ join(pwd, './data/xoshiro512-testset-2.csv'))
cls.seed_error_type = TypeError
cls.invalid_seed_types = [('apple',), (2 + 3j,), (3.1,)]
cls.invalid_seed_values = [(-2,), (np.empty((2, 2), dtype=np.int64),)]
@@ -363,7 +359,7 @@ class TestXoshiro512StarStar(Base):
class TestXorshift1024(Base):
@classmethod
def setup_class(cls):
- cls.brng = Xorshift1024
+ cls.bit_generator = Xorshift1024
cls.bits = 64
cls.dtype = np.uint64
cls.data1 = cls._read_csv(
@@ -378,7 +374,7 @@ class TestXorshift1024(Base):
class TestThreeFry(Base):
@classmethod
def setup_class(cls):
- cls.brng = ThreeFry
+ cls.bit_generator = ThreeFry
cls.bits = 64
cls.dtype = np.uint64
cls.data1 = cls._read_csv(
@@ -391,48 +387,17 @@ class TestThreeFry(Base):
(None, None, 2 ** 257 + 1)]
def test_set_key(self):
- brng = self.brng(*self.data1['seed'])
- state = brng.state
- keyed = self.brng(counter=state['state']['counter'],
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ state = bit_generator.state
+ keyed = self.bit_generator(counter=state['state']['counter'],
key=state['state']['key'])
- assert_state_equal(brng.state, keyed.state)
-
-
-class TestPCG64(Base):
- @classmethod
- def setup_class(cls):
- cls.brng = PCG64
- cls.bits = 64
- cls.dtype = np.uint64
- cls.data1 = cls._read_csv(join(pwd, './data/pcg64-testset-1.csv'))
- cls.data2 = cls._read_csv(join(pwd, './data/pcg64-testset-2.csv'))
- cls.seed_error_type = TypeError
- cls.invalid_seed_types = [(np.array([1, 2]),), (3.2,),
- (None, np.zeros(1))]
- cls.invalid_seed_values = [(-1,), (2 ** 129 + 1,), (None, -1),
- (None, 2 ** 129 + 1)]
-
- def test_seed_float_array(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(self.seed_error_type, rs.brng.seed, np.array([np.pi]))
- assert_raises(self.seed_error_type, rs.brng.seed, np.array([-np.pi]))
- assert_raises(self.seed_error_type, rs.brng.seed,
- np.array([np.pi, -np.pi]))
- assert_raises(self.seed_error_type, rs.brng.seed, np.array([0, np.pi]))
- assert_raises(self.seed_error_type, rs.brng.seed, [np.pi])
- assert_raises(self.seed_error_type, rs.brng.seed, [0, np.pi])
-
- def test_seed_out_of_range_array(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(self.seed_error_type, rs.brng.seed,
- [2 ** (2 * self.bits + 1)])
- assert_raises(self.seed_error_type, rs.brng.seed, [-1])
+ assert_state_equal(bit_generator.state, keyed.state)
class TestPhilox(Base):
@classmethod
def setup_class(cls):
- cls.brng = Philox
+ cls.bit_generator = Philox
cls.bits = 64
cls.dtype = np.uint64
cls.data1 = cls._read_csv(
@@ -445,17 +410,17 @@ class TestPhilox(Base):
(None, None, 2 ** 257 + 1)]
def test_set_key(self):
- brng = self.brng(*self.data1['seed'])
- state = brng.state
- keyed = self.brng(counter=state['state']['counter'],
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ state = bit_generator.state
+ keyed = self.bit_generator(counter=state['state']['counter'],
key=state['state']['key'])
- assert_state_equal(brng.state, keyed.state)
+ assert_state_equal(bit_generator.state, keyed.state)
class TestMT19937(Base):
@classmethod
def setup_class(cls):
- cls.brng = MT19937
+ cls.bit_generator = MT19937
cls.bits = 32
cls.dtype = np.uint32
cls.data1 = cls._read_csv(join(pwd, './data/mt19937-testset-1.csv'))
@@ -466,54 +431,54 @@ class TestMT19937(Base):
def test_seed_out_of_range(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(ValueError, rs.brng.seed, 2 ** (self.bits + 1))
- assert_raises(ValueError, rs.brng.seed, -1)
- assert_raises(ValueError, rs.brng.seed, 2 ** (2 * self.bits + 1))
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(ValueError, rs.bit_generator.seed, 2 ** (self.bits + 1))
+ assert_raises(ValueError, rs.bit_generator.seed, -1)
+ assert_raises(ValueError, rs.bit_generator.seed, 2 ** (2 * self.bits + 1))
def test_seed_out_of_range_array(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(ValueError, rs.brng.seed, [2 ** (self.bits + 1)])
- assert_raises(ValueError, rs.brng.seed, [-1])
- assert_raises(TypeError, rs.brng.seed, [2 ** (2 * self.bits + 1)])
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(ValueError, rs.bit_generator.seed, [2 ** (self.bits + 1)])
+ assert_raises(ValueError, rs.bit_generator.seed, [-1])
+ assert_raises(TypeError, rs.bit_generator.seed, [2 ** (2 * self.bits + 1)])
def test_seed_float(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(TypeError, rs.brng.seed, np.pi)
- assert_raises(TypeError, rs.brng.seed, -np.pi)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(TypeError, rs.bit_generator.seed, np.pi)
+ assert_raises(TypeError, rs.bit_generator.seed, -np.pi)
def test_seed_float_array(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- brng = rs.brng
- assert_raises(TypeError, brng.seed, np.array([np.pi]))
- assert_raises(TypeError, brng.seed, np.array([-np.pi]))
- assert_raises(TypeError, brng.seed, np.array([np.pi, -np.pi]))
- assert_raises(TypeError, brng.seed, np.array([0, np.pi]))
- assert_raises(TypeError, brng.seed, [np.pi])
- assert_raises(TypeError, brng.seed, [0, np.pi])
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ bit_generator = rs.bit_generator
+ assert_raises(TypeError, bit_generator.seed, np.array([np.pi]))
+ assert_raises(TypeError, bit_generator.seed, np.array([-np.pi]))
+ assert_raises(TypeError, bit_generator.seed, np.array([np.pi, -np.pi]))
+ assert_raises(TypeError, bit_generator.seed, np.array([0, np.pi]))
+ assert_raises(TypeError, bit_generator.seed, [np.pi])
+ assert_raises(TypeError, bit_generator.seed, [0, np.pi])
def test_state_tuple(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- brng = rs.brng
- state = brng.state
- desired = rs.randint(2 ** 16)
- tup = (state['brng'], state['state']['key'], state['state']['pos'])
- brng.state = tup
- actual = rs.randint(2 ** 16)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ bit_generator = rs.bit_generator
+ state = bit_generator.state
+ desired = rs.integers(2 ** 16)
+ tup = (state['bit_generator'], state['state']['key'], state['state']['pos'])
+ bit_generator.state = tup
+ actual = rs.integers(2 ** 16)
assert_equal(actual, desired)
tup = tup + (0, 0.0)
- brng.state = tup
- actual = rs.randint(2 ** 16)
+ bit_generator.state = tup
+ actual = rs.integers(2 ** 16)
assert_equal(actual, desired)
class TestDSFMT(Base):
@classmethod
def setup_class(cls):
- cls.brng = DSFMT
+ cls.bit_generator = DSFMT
cls.bits = 53
cls.dtype = np.uint64
cls.data1 = cls._read_csv(join(pwd, './data/dSFMT-testset-1.csv'))
@@ -524,74 +489,74 @@ class TestDSFMT(Base):
(np.array([2 ** 33, 2 ** 33]),)]
def test_uniform_double(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
+ rs = Generator(self.bit_generator(*self.data1['seed']))
assert_array_equal(uniform_from_dsfmt(self.data1['data']),
- rs.random_sample(1000))
+ rs.random(1000))
- rs = RandomGenerator(self.brng(*self.data2['seed']))
+ rs = Generator(self.bit_generator(*self.data2['seed']))
assert_equal(uniform_from_dsfmt(self.data2['data']),
- rs.random_sample(1000))
+ rs.random(1000))
def test_gauss_inv(self):
n = 25
- rs = RandomState(self.brng(*self.data1['seed']))
+ rs = RandomState(self.bit_generator(*self.data1['seed']))
gauss = rs.standard_normal(n)
assert_allclose(gauss,
gauss_from_uint(self.data1['data'], n, 'dsfmt'))
- rs = RandomState(self.brng(*self.data2['seed']))
+ rs = RandomState(self.bit_generator(*self.data2['seed']))
gauss = rs.standard_normal(25)
assert_allclose(gauss,
gauss_from_uint(self.data2['data'], n, 'dsfmt'))
def test_seed_out_of_range_array(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(ValueError, rs.brng.seed, [2 ** (self.bits + 1)])
- assert_raises(ValueError, rs.brng.seed, [-1])
- assert_raises(TypeError, rs.brng.seed, [2 ** (2 * self.bits + 1)])
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(ValueError, rs.bit_generator.seed, [2 ** (self.bits + 1)])
+ assert_raises(ValueError, rs.bit_generator.seed, [-1])
+ assert_raises(TypeError, rs.bit_generator.seed, [2 ** (2 * self.bits + 1)])
def test_seed_float(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(TypeError, rs.brng.seed, np.pi)
- assert_raises(TypeError, rs.brng.seed, -np.pi)
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(TypeError, rs.bit_generator.seed, np.pi)
+ assert_raises(TypeError, rs.bit_generator.seed, -np.pi)
def test_seed_float_array(self):
# GH #82
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- assert_raises(TypeError, rs.brng.seed, np.array([np.pi]))
- assert_raises(TypeError, rs.brng.seed, np.array([-np.pi]))
- assert_raises(TypeError, rs.brng.seed, np.array([np.pi, -np.pi]))
- assert_raises(TypeError, rs.brng.seed, np.array([0, np.pi]))
- assert_raises(TypeError, rs.brng.seed, [np.pi])
- assert_raises(TypeError, rs.brng.seed, [0, np.pi])
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ assert_raises(TypeError, rs.bit_generator.seed, np.array([np.pi]))
+ assert_raises(TypeError, rs.bit_generator.seed, np.array([-np.pi]))
+ assert_raises(TypeError, rs.bit_generator.seed, np.array([np.pi, -np.pi]))
+ assert_raises(TypeError, rs.bit_generator.seed, np.array([0, np.pi]))
+ assert_raises(TypeError, rs.bit_generator.seed, [np.pi])
+ assert_raises(TypeError, rs.bit_generator.seed, [0, np.pi])
def test_uniform_float(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
+ rs = Generator(self.bit_generator(*self.data1['seed']))
vals = uniform32_from_uint(self.data1['data'], self.bits)
- uniforms = rs.random_sample(len(vals), dtype=np.float32)
+ uniforms = rs.random(len(vals), dtype=np.float32)
assert_allclose(uniforms, vals)
assert_equal(uniforms.dtype, np.float32)
- rs = RandomGenerator(self.brng(*self.data2['seed']))
+ rs = Generator(self.bit_generator(*self.data2['seed']))
vals = uniform32_from_uint(self.data2['data'], self.bits)
- uniforms = rs.random_sample(len(vals), dtype=np.float32)
+ uniforms = rs.random(len(vals), dtype=np.float32)
assert_allclose(uniforms, vals)
assert_equal(uniforms.dtype, np.float32)
def test_buffer_reset(self):
- rs = RandomGenerator(self.brng(*self.data1['seed']))
- rs.random_sample(1)
- assert rs.brng.state['buffer_loc'] != 382
- rs.brng.seed(*self.data1['seed'])
- assert rs.brng.state['buffer_loc'] == 382
+ rs = Generator(self.bit_generator(*self.data1['seed']))
+ rs.random(1)
+ assert rs.bit_generator.state['buffer_loc'] != 382
+ rs.bit_generator.seed(*self.data1['seed'])
+ assert rs.bit_generator.state['buffer_loc'] == 382
class TestThreeFry32(Base):
@classmethod
def setup_class(cls):
- cls.brng = ThreeFry32
+ cls.bit_generator = ThreeFry32
cls.bits = 32
cls.dtype = np.uint32
cls.data1 = cls._read_csv(join(pwd, './data/threefry32-testset-1.csv'))
@@ -602,23 +567,8 @@ class TestThreeFry32(Base):
(None, None, 2 ** 129 + 1)]
def test_set_key(self):
- brng = self.brng(*self.data1['seed'])
- state = brng.state
- keyed = self.brng(counter=state['state']['counter'],
+ bit_generator = self.bit_generator(*self.data1['seed'])
+ state = bit_generator.state
+ keyed = self.bit_generator(counter=state['state']['counter'],
key=state['state']['key'])
- assert_state_equal(brng.state, keyed.state)
-
-
-class TestPCG32(TestPCG64):
- @classmethod
- def setup_class(cls):
- cls.brng = PCG32
- cls.bits = 32
- cls.dtype = np.uint32
- cls.data1 = cls._read_csv(join(pwd, './data/pcg32-testset-1.csv'))
- cls.data2 = cls._read_csv(join(pwd, './data/pcg32-testset-2.csv'))
- cls.seed_error_type = TypeError
- cls.invalid_seed_types = [(np.array([1, 2]),), (3.2,),
- (None, np.zeros(1))]
- cls.invalid_seed_values = [(-1,), (2 ** 129 + 1,), (None, -1),
- (None, 2 ** 129 + 1)]
+ assert_state_equal(bit_generator.state, keyed.state)
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py
index ace5c230c..3bb3bd791 100644
--- a/numpy/random/tests/test_generator_mt19937.py
+++ b/numpy/random/tests/test_generator_mt19937.py
@@ -9,32 +9,32 @@ from numpy.testing import (
assert_warns, assert_no_warnings, assert_array_equal,
assert_array_almost_equal, suppress_warnings)
-from numpy.random import RandomGenerator, MT19937
+from numpy.random import Generator, MT19937
-random = RandomGenerator(MT19937())
+random = Generator(MT19937())
@pytest.fixture(scope='module', params=[True, False])
-def closed(request):
+def endpoint(request):
return request.param
class TestSeed(object):
def test_scalar(self):
- s = RandomGenerator(MT19937(0))
- assert_equal(s.randint(1000), 684)
- s = RandomGenerator(MT19937(4294967295))
- assert_equal(s.randint(1000), 419)
+ s = Generator(MT19937(0))
+ assert_equal(s.integers(1000), 684)
+ s = Generator(MT19937(4294967295))
+ assert_equal(s.integers(1000), 419)
def test_array(self):
- s = RandomGenerator(MT19937(range(10)))
- assert_equal(s.randint(1000), 468)
- s = RandomGenerator(MT19937(np.arange(10)))
- assert_equal(s.randint(1000), 468)
- s = RandomGenerator(MT19937([0]))
- assert_equal(s.randint(1000), 973)
- s = RandomGenerator(MT19937([4294967295]))
- assert_equal(s.randint(1000), 265)
+ s = Generator(MT19937(range(10)))
+ assert_equal(s.integers(1000), 468)
+ s = Generator(MT19937(np.arange(10)))
+ assert_equal(s.integers(1000), 468)
+ s = Generator(MT19937([0]))
+ assert_equal(s.integers(1000), 973)
+ s = Generator(MT19937([4294967295]))
+ assert_equal(s.integers(1000), 265)
def test_invalid_scalar(self):
# seed must be an unsigned 32 bit integer
@@ -49,8 +49,8 @@ class TestSeed(object):
assert_raises(ValueError, MT19937, [1, 2, 4294967296])
assert_raises(ValueError, MT19937, [1, -2, 4294967296])
- def test_noninstantized_brng(self):
- assert_raises(ValueError, RandomGenerator, MT19937)
+ def test_noninstantized_bitgen(self):
+ assert_raises(ValueError, Generator, MT19937)
class TestBinomial(object):
@@ -76,8 +76,8 @@ class TestMultinomial(object):
random.multinomial(100, [0.2, 0.8, 0.0, 0.0, 0.0])
def test_int_negative_interval(self):
- assert_(-5 <= random.randint(-5, -1) < -1)
- x = random.randint(-5, -1, 5)
+ assert_(-5 <= random.integers(-5, -1) < -1)
+ x = random.integers(-5, -1, 5)
assert_(np.all(-5 <= x))
assert_(np.all(x < -1))
@@ -107,23 +107,23 @@ class TestMultinomial(object):
class TestSetState(object):
def setup(self):
self.seed = 1234567890
- self.rg = RandomGenerator(MT19937(self.seed))
- self.brng = self.rg.brng
- self.state = self.brng.state
- self.legacy_state = (self.state['brng'],
+ self.rg = Generator(MT19937(self.seed))
+ self.bit_generator = self.rg.bit_generator
+ self.state = self.bit_generator.state
+ self.legacy_state = (self.state['bit_generator'],
self.state['state']['key'],
self.state['state']['pos'])
def test_basic(self):
old = self.rg.tomaxint(16)
- self.brng.state = self.state
+ self.bit_generator.state = self.state
new = self.rg.tomaxint(16)
assert_(np.all(old == new))
def test_gaussian_reset(self):
# Make sure the cached every-other-Gaussian is reset.
old = self.rg.standard_normal(size=3)
- self.brng.state = self.state
+ self.bit_generator.state = self.state
new = self.rg.standard_normal(size=3)
assert_(np.all(old == new))
@@ -132,9 +132,9 @@ class TestSetState(object):
# cached Gaussian is restored.
self.rg.standard_normal()
- state = self.brng.state
+ state = self.bit_generator.state
old = self.rg.standard_normal(size=3)
- self.brng.state = state
+ self.bit_generator.state = state
new = self.rg.standard_normal(size=3)
assert_(np.all(old == new))
@@ -144,84 +144,84 @@ class TestSetState(object):
self.rg.negative_binomial(0.5, 0.5)
-class TestRandint(object):
- rfunc = random.randint
+class TestIntegers(object):
+ rfunc = random.integers
# valid integer/boolean types
itype = [bool, np.int8, np.uint8, np.int16, np.uint16,
np.int32, np.uint32, np.int64, np.uint64]
- def test_unsupported_type(self, closed):
- assert_raises(TypeError, self.rfunc, 1, closed=closed, dtype=float)
+ def test_unsupported_type(self, endpoint):
+ assert_raises(TypeError, self.rfunc, 1, endpoint=endpoint, dtype=float)
- def test_bounds_checking(self, closed):
+ def test_bounds_checking(self, endpoint):
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd,
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1,
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, ubnd, lbnd,
- closed=closed, dtype=dt)
- assert_raises(ValueError, self.rfunc, 1, 0, closed=closed,
+ endpoint=endpoint, dtype=dt)
+ assert_raises(ValueError, self.rfunc, 1, 0, endpoint=endpoint,
dtype=dt)
assert_raises(ValueError, self.rfunc, [lbnd - 1], ubnd,
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, [lbnd], [ubnd + 1],
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, [ubnd], [lbnd],
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, 1, [0],
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
- def test_bounds_checking_array(self, closed):
+ def test_bounds_checking_array(self, endpoint):
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
- ubnd = 2 if dt is bool else np.iinfo(dt).max + (not closed)
+ ubnd = 2 if dt is bool else np.iinfo(dt).max + (not endpoint)
assert_raises(ValueError, self.rfunc, [
- lbnd - 1] * 2, [ubnd] * 2, closed=closed, dtype=dt)
+ lbnd - 1] * 2, [ubnd] * 2, endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, [
- lbnd] * 2, [ubnd + 1] * 2, closed=closed, dtype=dt)
+ lbnd] * 2, [ubnd + 1] * 2, endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, ubnd, [lbnd] * 2,
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
assert_raises(ValueError, self.rfunc, [1] * 2, 0,
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
- def test_rng_zero_and_extremes(self, closed):
+ def test_rng_zero_and_extremes(self, endpoint):
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
- is_open = not closed
+ ubnd = ubnd - 1 if endpoint else ubnd
+ is_open = not endpoint
tgt = ubnd - 1
assert_equal(self.rfunc(tgt, tgt + is_open, size=1000,
- closed=closed, dtype=dt), tgt)
+ endpoint=endpoint, dtype=dt), tgt)
assert_equal(self.rfunc([tgt], tgt + is_open, size=1000,
- closed=closed, dtype=dt), tgt)
+ endpoint=endpoint, dtype=dt), tgt)
tgt = lbnd
assert_equal(self.rfunc(tgt, tgt + is_open, size=1000,
- closed=closed, dtype=dt), tgt)
+ endpoint=endpoint, dtype=dt), tgt)
assert_equal(self.rfunc(tgt, [tgt + is_open], size=1000,
- closed=closed, dtype=dt), tgt)
+ endpoint=endpoint, dtype=dt), tgt)
tgt = (lbnd + ubnd) // 2
assert_equal(self.rfunc(tgt, tgt + is_open, size=1000,
- closed=closed, dtype=dt), tgt)
+ endpoint=endpoint, dtype=dt), tgt)
assert_equal(self.rfunc([tgt], [tgt + is_open],
- size=1000, closed=closed, dtype=dt), tgt)
+ size=1000, endpoint=endpoint, dtype=dt), tgt)
- def test_rng_zero_and_extremes_array(self, closed):
+ def test_rng_zero_and_extremes_array(self, endpoint):
size = 1000
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
tgt = ubnd - 1
assert_equal(self.rfunc([tgt], [tgt + 1],
@@ -247,73 +247,73 @@ class TestRandint(object):
assert_equal(self.rfunc(
[tgt] * size, [tgt + 1] * size, size=size, dtype=dt), tgt)
- def test_full_range(self, closed):
+ def test_full_range(self, endpoint):
# Test for ticket #1690
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
try:
- self.rfunc(lbnd, ubnd, closed=closed, dtype=dt)
+ self.rfunc(lbnd, ubnd, endpoint=endpoint, dtype=dt)
except Exception as e:
raise AssertionError("No error should have been raised, "
"but one was with the following "
"message:\n\n%s" % str(e))
- def test_full_range_array(self, closed):
+ def test_full_range_array(self, endpoint):
# Test for ticket #1690
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
try:
- self.rfunc([lbnd] * 2, [ubnd], closed=closed, dtype=dt)
+ self.rfunc([lbnd] * 2, [ubnd], endpoint=endpoint, dtype=dt)
except Exception as e:
raise AssertionError("No error should have been raised, "
"but one was with the following "
"message:\n\n%s" % str(e))
- def test_in_bounds_fuzz(self, closed):
+ def test_in_bounds_fuzz(self, endpoint):
# Don't use fixed seed
- random.brng.seed()
+ random.bit_generator.seed()
for dt in self.itype[1:]:
for ubnd in [4, 8, 16]:
- vals = self.rfunc(2, ubnd - closed, size=2 ** 16,
- closed=closed, dtype=dt)
+ vals = self.rfunc(2, ubnd - endpoint, size=2 ** 16,
+ endpoint=endpoint, dtype=dt)
assert_(vals.max() < ubnd)
assert_(vals.min() >= 2)
- vals = self.rfunc(0, 2 - closed, size=2 ** 16, closed=closed,
+ vals = self.rfunc(0, 2 - endpoint, size=2 ** 16, endpoint=endpoint,
dtype=bool)
assert_(vals.max() < 2)
assert_(vals.min() >= 0)
- def test_scalar_array_equiv(self, closed):
+ def test_scalar_array_equiv(self, endpoint):
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
size = 1000
- random.brng.seed(1234)
- scalar = self.rfunc(lbnd, ubnd, size=size, closed=closed, dtype=dt)
+ random.bit_generator.seed(1234)
+ scalar = self.rfunc(lbnd, ubnd, size=size, endpoint=endpoint, dtype=dt)
- random.brng.seed(1234)
+ random.bit_generator.seed(1234)
scalar_array = self.rfunc([lbnd], [ubnd], size=size,
- closed=closed, dtype=dt)
+ endpoint=endpoint, dtype=dt)
- random.brng.seed(1234)
+ random.bit_generator.seed(1234)
array = self.rfunc([lbnd] * size, [ubnd] *
- size, size=size, closed=closed, dtype=dt)
+ size, size=size, endpoint=endpoint, dtype=dt)
assert_array_equal(scalar, scalar_array)
assert_array_equal(scalar, array)
- def test_repeatability(self, closed):
+ def test_repeatability(self, endpoint):
import hashlib
# We use a md5 hash of generated sequences of 1000 samples
# in the range [0, 6) for all but bool, where the range
@@ -329,77 +329,77 @@ class TestRandint(object):
'uint8': '27dd30c4e08a797063dffac2490b0be6'}
for dt in self.itype[1:]:
- random.brng.seed(1234)
+ random.bit_generator.seed(1234)
# view as little endian for hash
if sys.byteorder == 'little':
- val = self.rfunc(0, 6 - closed, size=1000, closed=closed,
+ val = self.rfunc(0, 6 - endpoint, size=1000, endpoint=endpoint,
dtype=dt)
else:
- val = self.rfunc(0, 6 - closed, size=1000, closed=closed,
+ val = self.rfunc(0, 6 - endpoint, size=1000, endpoint=endpoint,
dtype=dt).byteswap()
res = hashlib.md5(val.view(np.int8)).hexdigest()
assert_(tgt[np.dtype(dt).name] == res)
# bools do not depend on endianness
- random.brng.seed(1234)
- val = self.rfunc(0, 2 - closed, size=1000, closed=closed,
+ random.bit_generator.seed(1234)
+ val = self.rfunc(0, 2 - endpoint, size=1000, endpoint=endpoint,
dtype=bool).view(np.int8)
res = hashlib.md5(val).hexdigest()
assert_(tgt[np.dtype(bool).name] == res)
- def test_repeatability_broadcasting(self, closed):
+ def test_repeatability_broadcasting(self, endpoint):
for dt in self.itype:
lbnd = 0 if dt in (np.bool, bool, np.bool_) else np.iinfo(dt).min
ubnd = 2 if dt in (
np.bool, bool, np.bool_) else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
# view as little endian for hash
- random.brng.seed(1234)
- val = self.rfunc(lbnd, ubnd, size=1000, closed=closed, dtype=dt)
+ random.bit_generator.seed(1234)
+ val = self.rfunc(lbnd, ubnd, size=1000, endpoint=endpoint, dtype=dt)
- random.brng.seed(1234)
- val_bc = self.rfunc([lbnd] * 1000, ubnd, closed=closed, dtype=dt)
+ random.bit_generator.seed(1234)
+ val_bc = self.rfunc([lbnd] * 1000, ubnd, endpoint=endpoint, dtype=dt)
assert_array_equal(val, val_bc)
- random.brng.seed(1234)
- val_bc = self.rfunc([lbnd] * 1000, [ubnd] * 1000, closed=closed,
+ random.bit_generator.seed(1234)
+ val_bc = self.rfunc([lbnd] * 1000, [ubnd] * 1000, endpoint=endpoint,
dtype=dt)
assert_array_equal(val, val_bc)
- def test_int64_uint64_broadcast_exceptions(self, closed):
+ def test_int64_uint64_broadcast_exceptions(self, endpoint):
configs = {np.uint64: ((0, 2**65), (-1, 2**62), (10, 9), (0, 0)),
np.int64: ((0, 2**64), (-(2**64), 2**62), (10, 9), (0, 0),
(-2**63-1, -2**63-1))}
for dtype in configs:
for config in configs[dtype]:
low, high = config
- high = high - closed
+ high = high - endpoint
low_a = np.array([[low]*10])
high_a = np.array([high] * 10)
- assert_raises(ValueError, random.randint, low, high,
- closed=closed, dtype=dtype)
- assert_raises(ValueError, random.randint, low_a, high,
- closed=closed, dtype=dtype)
- assert_raises(ValueError, random.randint, low, high_a,
- closed=closed, dtype=dtype)
- assert_raises(ValueError, random.randint, low_a, high_a,
- closed=closed, dtype=dtype)
+ assert_raises(ValueError, random.integers, low, high,
+ endpoint=endpoint, dtype=dtype)
+ assert_raises(ValueError, random.integers, low_a, high,
+ endpoint=endpoint, dtype=dtype)
+ assert_raises(ValueError, random.integers, low, high_a,
+ endpoint=endpoint, dtype=dtype)
+ assert_raises(ValueError, random.integers, low_a, high_a,
+ endpoint=endpoint, dtype=dtype)
low_o = np.array([[low]*10], dtype=np.object)
high_o = np.array([high] * 10, dtype=np.object)
- assert_raises(ValueError, random.randint, low_o, high,
- closed=closed, dtype=dtype)
- assert_raises(ValueError, random.randint, low, high_o,
- closed=closed, dtype=dtype)
- assert_raises(ValueError, random.randint, low_o, high_o,
- closed=closed, dtype=dtype)
-
- def test_int64_uint64_corner_case(self, closed):
+ assert_raises(ValueError, random.integers, low_o, high,
+ endpoint=endpoint, dtype=dtype)
+ assert_raises(ValueError, random.integers, low, high_o,
+ endpoint=endpoint, dtype=dtype)
+ assert_raises(ValueError, random.integers, low_o, high_o,
+ endpoint=endpoint, dtype=dtype)
+
+ def test_int64_uint64_corner_case(self, endpoint):
# When stored in Numpy arrays, `lbnd` is casted
# as np.int64, and `ubnd` is casted as np.uint64.
# Checking whether `lbnd` >= `ubnd` used to be
@@ -415,58 +415,58 @@ class TestRandint(object):
dt = np.int64
tgt = np.iinfo(np.int64).max
lbnd = np.int64(np.iinfo(np.int64).max)
- ubnd = np.uint64(np.iinfo(np.int64).max + 1 - closed)
+ ubnd = np.uint64(np.iinfo(np.int64).max + 1 - endpoint)
# None of these function calls should
# generate a ValueError now.
- actual = random.randint(lbnd, ubnd, closed=closed, dtype=dt)
+ actual = random.integers(lbnd, ubnd, endpoint=endpoint, dtype=dt)
assert_equal(actual, tgt)
- def test_respect_dtype_singleton(self, closed):
+ def test_respect_dtype_singleton(self, endpoint):
# See gh-7203
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
dt = np.bool_ if dt is bool else dt
- sample = self.rfunc(lbnd, ubnd, closed=closed, dtype=dt)
+ sample = self.rfunc(lbnd, ubnd, endpoint=endpoint, dtype=dt)
assert_equal(sample.dtype, dt)
for dt in (bool, int, np.long):
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
# gh-7284: Ensure that we get Python data types
- sample = self.rfunc(lbnd, ubnd, closed=closed, dtype=dt)
+ sample = self.rfunc(lbnd, ubnd, endpoint=endpoint, dtype=dt)
assert not hasattr(sample, 'dtype')
assert_equal(type(sample), dt)
- def test_respect_dtype_array(self, closed):
+ def test_respect_dtype_array(self, endpoint):
# See gh-7203
for dt in self.itype:
lbnd = 0 if dt is bool else np.iinfo(dt).min
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
- ubnd = ubnd - 1 if closed else ubnd
+ ubnd = ubnd - 1 if endpoint else ubnd
dt = np.bool_ if dt is bool else dt
- sample = self.rfunc([lbnd], [ubnd], closed=closed, dtype=dt)
+ sample = self.rfunc([lbnd], [ubnd], endpoint=endpoint, dtype=dt)
assert_equal(sample.dtype, dt)
- sample = self.rfunc([lbnd] * 2, [ubnd] * 2, closed=closed,
+ sample = self.rfunc([lbnd] * 2, [ubnd] * 2, endpoint=endpoint,
dtype=dt)
assert_equal(sample.dtype, dt)
- def test_zero_size(self, closed):
+ def test_zero_size(self, endpoint):
# See gh-7203
for dt in self.itype:
- sample = self.rfunc(0, 0, (3, 0, 4), closed=closed, dtype=dt)
+ sample = self.rfunc(0, 0, (3, 0, 4), endpoint=endpoint, dtype=dt)
assert sample.shape == (3, 0, 4)
assert sample.dtype == dt
- assert self.rfunc(0, -10, 0, closed=closed, dtype=dt).shape == (0,)
- assert_equal(random.randint(0, 0, size=(3, 0, 4)).shape, (3, 0, 4))
- assert_equal(random.randint(0, -10, size=0).shape, (0,))
- assert_equal(random.randint(10, 10, size=0).shape, (0,))
+ assert self.rfunc(0, -10, 0, endpoint=endpoint, dtype=dt).shape == (0,)
+ assert_equal(random.integers(0, 0, size=(3, 0, 4)).shape, (3, 0, 4))
+ assert_equal(random.integers(0, -10, size=0).shape, (0,))
+ assert_equal(random.integers(10, 10, size=0).shape, (0,))
class TestRandomDist(object):
@@ -476,178 +476,111 @@ class TestRandomDist(object):
def setup(self):
self.seed = 1234567890
- def test_rand(self):
- random.brng.seed(self.seed)
- actual = random.rand(3, 2)
- desired = np.array([[0.61879477158567997, 0.59162362775974664],
- [0.88868358904449662, 0.89165480011560816],
- [0.4575674820298663, 0.7781880808593471]])
- assert_array_almost_equal(actual, desired, decimal=15)
-
- def test_rand_singleton(self):
- random.brng.seed(self.seed)
- actual = random.rand()
- desired = 0.61879477158567997
- assert_array_almost_equal(actual, desired, decimal=15)
-
- def test_randn(self):
- random.brng.seed(self.seed)
- actual = random.randn(3, 2)
- desired = np.array([[-3.472754000610961, -0.108938564229143],
- [-0.245965753396411, -0.704101550261701],
- [0.360102487116356, 0.127832101772367]])
- assert_array_almost_equal(actual, desired, decimal=15)
-
- random.brng.seed(self.seed)
- actual = random.randn()
- assert_array_almost_equal(actual, desired[0, 0], decimal=15)
-
- def test_randint(self):
- random.brng.seed(self.seed)
- actual = random.randint(-99, 99, size=(3, 2))
+ def test_integers(self):
+ random.bit_generator.seed(self.seed)
+ actual = random.integers(-99, 99, size=(3, 2))
desired = np.array([[31, 3],
[-52, 41],
[-48, -66]])
assert_array_equal(actual, desired)
- def test_randint_masked(self):
+ def test_integers_masked(self):
# Test masked rejection sampling algorithm to generate array of
# uint32 in an interval.
- random.brng.seed(self.seed)
- actual = random.randint(0, 99, size=(3, 2), dtype=np.uint32,
- use_masked=True)
+ random.bit_generator.seed(self.seed)
+ actual = random.integers(0, 99, size=(3, 2), dtype=np.uint32)
desired = np.array([[2, 47],
[12, 51],
[33, 43]], dtype=np.uint32)
assert_array_equal(actual, desired)
- def test_randint_lemire_32(self):
- # Test lemire algorithm to generate array of uint32 in an interval.
- random.brng.seed(self.seed)
- actual = random.randint(0, 99, size=(3, 2), dtype=np.uint32,
- use_masked=False)
- desired = np.array([[61, 33],
- [58, 14],
- [87, 23]], dtype=np.uint32)
- assert_array_equal(actual, desired)
-
- def test_randint_lemire_64(self):
- # Test lemire algorithm to generate array of uint64 in an interval.
- random.brng.seed(self.seed)
- actual = random.randint(0, 99 + 0xFFFFFFFFF, size=(3, 2),
- dtype=np.uint64, use_masked=False)
- desired = np.array([[42523252834, 40656066204],
- [61069871386, 61274051182],
- [31443797706, 53476677934]], dtype=np.uint64)
- assert_array_equal(actual, desired)
-
- def test_random_integers(self):
- random.brng.seed(self.seed)
- with suppress_warnings() as sup:
- w = sup.record(DeprecationWarning)
- actual = random.random_integers(-99, 99, size=(3, 2))
- assert_(len(w) == 1)
+ def test_integers_closed(self):
+ random.bit_generator.seed(self.seed)
+ actual = random.integers(-99, 99, size=(3, 2), endpoint=True)
desired = np.array([[31, 3],
[-52, 41],
[-48, -66]])
assert_array_equal(actual, desired)
- def test_random_integers_max_int(self):
- # Tests whether random_integers can generate the
+ def test_integers_max_int(self):
+ # Tests whether integers with closed=True can generate the
# maximum allowed Python int that can be converted
# into a C long. Previous implementations of this
# method have thrown an OverflowError when attempting
# to generate this integer.
- with suppress_warnings() as sup:
- w = sup.record(DeprecationWarning)
- actual = random.random_integers(np.iinfo('l').max,
- np.iinfo('l').max)
- assert_(len(w) == 1)
+ actual = random.integers(np.iinfo('l').max,
+ np.iinfo('l').max, endpoint=True)
desired = np.iinfo('l').max
assert_equal(actual, desired)
- def test_random_integers_deprecated(self):
- with warnings.catch_warnings():
- warnings.simplefilter("error", DeprecationWarning)
-
- # DeprecationWarning raised with high == None
- assert_raises(DeprecationWarning,
- random.random_integers,
- np.iinfo('l').max)
-
- # DeprecationWarning raised with high != None
- assert_raises(DeprecationWarning,
- random.random_integers,
- np.iinfo('l').max, np.iinfo('l').max)
-
- def test_random_sample(self):
- random.brng.seed(self.seed)
- actual = random.random_sample((3, 2))
+ def test_random(self):
+ random.bit_generator.seed(self.seed)
+ actual = random.random((3, 2))
desired = np.array([[0.61879477158567997, 0.59162362775974664],
[0.88868358904449662, 0.89165480011560816],
[0.4575674820298663, 0.7781880808593471]])
assert_array_almost_equal(actual, desired, decimal=15)
- random.brng.seed(self.seed)
- actual = random.random_sample()
+ random.bit_generator.seed(self.seed)
+ actual = random.random()
assert_array_almost_equal(actual, desired[0, 0], decimal=15)
- def test_random_sample_float(self):
- random.brng.seed(self.seed)
- actual = random.random_sample((3, 2))
+ def test_random_float(self):
+ random.bit_generator.seed(self.seed)
+ actual = random.random((3, 2))
desired = np.array([[0.6187948, 0.5916236],
[0.8886836, 0.8916548],
[0.4575675, 0.7781881]])
assert_array_almost_equal(actual, desired, decimal=7)
- def test_random_sample_float_scalar(self):
- random.brng.seed(self.seed)
- actual = random.random_sample(dtype=np.float32)
+ def test_random_float_scalar(self):
+ random.bit_generator.seed(self.seed)
+ actual = random.random(dtype=np.float32)
desired = 0.6187948
assert_array_almost_equal(actual, desired, decimal=7)
- def test_random_sample_unsupported_type(self):
- assert_raises(TypeError, random.random_sample, dtype='int32')
+ def test_random_unsupported_type(self):
+ assert_raises(TypeError, random.random, dtype='int32')
def test_choice_uniform_replace(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice(4, 4)
desired = np.array([2, 3, 2, 3], dtype=np.int64)
assert_array_equal(actual, desired)
def test_choice_nonuniform_replace(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice(4, 4, p=[0.4, 0.4, 0.1, 0.1])
desired = np.array([1, 1, 2, 2], dtype=np.int64)
assert_array_equal(actual, desired)
def test_choice_uniform_noreplace(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice(4, 3, replace=False)
desired = np.array([0, 2, 3], dtype=np.int64)
assert_array_equal(actual, desired)
def test_choice_nonuniform_noreplace(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice(4, 3, replace=False, p=[0.1, 0.3, 0.5, 0.1])
desired = np.array([2, 3, 1], dtype=np.int64)
assert_array_equal(actual, desired)
def test_choice_noninteger(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice(['a', 'b', 'c', 'd'], 4)
desired = np.array(['c', 'd', 'c', 'd'])
assert_array_equal(actual, desired)
def test_choice_multidimensional_default_axis(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice([[0, 1], [2, 3], [4, 5], [6, 7]], 3)
desired = np.array([[4, 5], [6, 7], [4, 5]])
assert_array_equal(actual, desired)
def test_choice_multidimensional_custom_axis(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice([[0, 1], [2, 3], [4, 5], [6, 7]], 1, axis=1)
desired = np.array([[0], [2], [4], [6]])
assert_array_equal(actual, desired)
@@ -707,9 +640,9 @@ class TestRandomDist(object):
assert_equal(random.choice(np.arange(6), s, replace=True).shape, s)
# Check zero-size
- assert_equal(random.randint(0, 0, size=(3, 0, 4)).shape, (3, 0, 4))
- assert_equal(random.randint(0, -10, size=0).shape, (0,))
- assert_equal(random.randint(10, 10, size=0).shape, (0,))
+ assert_equal(random.integers(0, 0, size=(3, 0, 4)).shape, (3, 0, 4))
+ assert_equal(random.integers(0, -10, size=0).shape, (0,))
+ assert_equal(random.integers(10, 10, size=0).shape, (0,))
assert_equal(random.choice(0, size=0).shape, (0,))
assert_equal(random.choice([], size=(0,)).shape, (0,))
assert_equal(random.choice(['a', 'b'], size=(3, 0, 4)).shape,
@@ -737,7 +670,7 @@ class TestRandomDist(object):
import hashlib
choice_hash = '6395868be877d27518c832213c17977c'
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.choice(10000, 5000, replace=False)
if sys.byteorder != 'little':
actual = actual.byteswap()
@@ -745,7 +678,7 @@ class TestRandomDist(object):
assert_(choice_hash == res)
def test_bytes(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.bytes(10)
desired = b'\x82Ui\x9e\xff\x97+Wf\xa5'
assert_equal(actual, desired)
@@ -770,7 +703,7 @@ class TestRandomDist(object):
lambda x: np.asarray([(i, i) for i in x],
[("a", object, 1),
("b", np.int32, 1)])]:
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
random.shuffle(alist)
actual = alist
@@ -792,19 +725,19 @@ class TestRandomDist(object):
sorted(b.data[~b.mask]), sorted(b_orig.data[~b_orig.mask]))
def test_permutation(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
alist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
actual = random.permutation(alist)
desired = [0, 1, 9, 6, 2, 4, 5, 8, 7, 3]
assert_array_equal(actual, desired)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
arr_2d = np.atleast_2d([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]).T
actual = random.permutation(arr_2d)
assert_array_equal(actual, np.atleast_2d(desired).T)
def test_beta(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.beta(.1, .9, size=(3, 2))
desired = np.array(
[[1.45341850513746058e-02, 5.31297615662868145e-04],
@@ -813,20 +746,20 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_binomial(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.binomial(100.123, .456, size=(3, 2))
desired = np.array([[37, 43],
[42, 48],
[46, 45]])
assert_array_equal(actual, desired)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.binomial(100.123, .456)
desired = 37
assert_array_equal(actual, desired)
def test_chisquare(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.chisquare(50, size=(3, 2))
desired = np.array([[22.2534560369812, 46.9302393710074],
[52.9974164611614, 85.3559029505718],
@@ -834,7 +767,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=13)
def test_dirichlet(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
alpha = np.array([51.72840233779265162, 39.74494232180943953])
actual = random.dirichlet(alpha, size=(3, 2))
desired = np.array([[[0.444382290764855, 0.555617709235145],
@@ -847,7 +780,7 @@ class TestRandomDist(object):
bad_alpha = np.array([5.4e-01, -1.0e-16])
assert_raises(ValueError, random.dirichlet, bad_alpha)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
alpha = np.array([51.72840233779265162, 39.74494232180943953])
actual = random.dirichlet(alpha)
assert_array_almost_equal(actual, desired[0, 0], decimal=15)
@@ -870,7 +803,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.dirichlet, alpha)
def test_exponential(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.exponential(1.1234, size=(3, 2))
desired = np.array([[5.350682337747634, 1.152307441755771],
[3.867015473358779, 1.538765912839396],
@@ -882,7 +815,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.exponential, scale=-0.)
def test_f(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.f(12, 77, size=(3, 2))
desired = np.array([[0.809498839488467, 2.867222762455471],
[0.588036831639353, 1.012185639664636],
@@ -890,7 +823,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_gamma(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.gamma(5, 3, size=(3, 2))
desired = np.array([[12.46569350177219, 16.46580642087044],
[43.65744473309084, 11.98722785682592],
@@ -902,7 +835,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.gamma, shape=-0., scale=-0.)
def test_geometric(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.geometric(.123456789, size=(3, 2))
desired = np.array([[8, 7],
[17, 17],
@@ -919,7 +852,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.geometric, [np.nan] * 10)
def test_gumbel(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.gumbel(loc=.123456789, scale=2.0, size=(3, 2))
desired = np.array([[0.19591898743416816, 0.34405539668096674],
[-1.4492522252274278, -1.47374816298446865],
@@ -931,7 +864,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.gumbel, scale=-0.)
def test_hypergeometric(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.hypergeometric(10.1, 5.5, 14, size=(3, 2))
desired = np.array([[10, 10],
[10, 10],
@@ -957,7 +890,7 @@ class TestRandomDist(object):
assert_array_equal(actual, desired)
def test_laplace(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.laplace(loc=.123456789, scale=2.0, size=(3, 2))
desired = np.array([[0.66599721112760157, 0.52829452552221945],
[3.12791959514407125, 3.18202813572992005],
@@ -969,7 +902,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.laplace, scale=-0.)
def test_logistic(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.logistic(loc=.123456789, scale=2.0, size=(3, 2))
desired = np.array([[1.09232835305011444, 0.8648196662399954],
[4.27818590694950185, 4.33897006346929714],
@@ -977,7 +910,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_lognormal(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.lognormal(mean=.123456789, sigma=2.0, size=(3, 2))
desired = np.array([[1.0894838661036e-03, 9.0990021488311e-01],
[6.9178869932225e-01, 2.7672077560016e-01],
@@ -989,7 +922,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.lognormal, sigma=-0.)
def test_logseries(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.logseries(p=.923456789, size=(3, 2))
desired = np.array([[2, 2],
[6, 17],
@@ -1002,7 +935,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.logseries, [np.nan] * 10)
def test_multinomial(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.multinomial(20, [1 / 6.] * 6, size=(3, 2))
desired = np.array([[[4, 3, 5, 4, 2, 2],
[5, 2, 8, 2, 2, 1]],
@@ -1013,7 +946,7 @@ class TestRandomDist(object):
assert_array_equal(actual, desired)
def test_multivariate_normal(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
mean = (.123456789, 10)
cov = [[1, 0], [0, 1]]
size = (3, 2)
@@ -1064,7 +997,7 @@ class TestRandomDist(object):
mu, np.eye(3))
def test_negative_binomial(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.negative_binomial(n=100, p=.12345, size=(3, 2))
desired = np.array([[521, 736],
[665, 690],
@@ -1078,7 +1011,7 @@ class TestRandomDist(object):
[np.nan] * 10)
def test_noncentral_chisquare(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.noncentral_chisquare(df=5, nonc=5, size=(3, 2))
desired = np.array([[9.47783251920357, 10.02066178260461],
[3.15869984192364, 10.5581565031544],
@@ -1091,7 +1024,7 @@ class TestRandomDist(object):
[1.41985055641800, 0.15451287602753]])
assert_array_almost_equal(actual, desired, decimal=14)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.noncentral_chisquare(df=5, nonc=0, size=(3, 2))
desired = np.array([[3.64881368071039, 5.48224544747803],
[20.41999842025404, 3.44075915187367],
@@ -1099,7 +1032,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=14)
def test_noncentral_f(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.noncentral_f(dfnum=5, dfden=2, nonc=1,
size=(3, 2))
desired = np.array([[1.22680230963236, 2.56457837623956],
@@ -1108,12 +1041,12 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=14)
def test_noncentral_f_nan(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.noncentral_f(dfnum=5, dfden=2, nonc=np.nan)
assert np.isnan(actual)
def test_normal(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.normal(loc=.123456789, scale=2.0, size=(3, 2))
desired = np.array([[-6.822051212221923, -0.094420339458285],
[-0.368474717792823, -1.284746311523402],
@@ -1125,7 +1058,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.normal, scale=-0.)
def test_pareto(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.pareto(a=.123456789, size=(3, 2))
desired = np.array([[5.6883528121891552e+16, 4.0569373841667057e+03],
[1.2854967019379475e+12, 6.5833156486851483e+04],
@@ -1139,7 +1072,7 @@ class TestRandomDist(object):
np.testing.assert_array_almost_equal_nulp(actual, desired, nulp=30)
def test_poisson(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.poisson(lam=.123456789, size=(3, 2))
desired = np.array([[0, 0],
[1, 0],
@@ -1158,7 +1091,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.poisson, [np.nan] * 10)
def test_power(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.power(a=.123456789, size=(3, 2))
desired = np.array([[9.328833342693975e-01, 2.742250409261003e-02],
[7.684513237993961e-01, 9.297548209160028e-02],
@@ -1166,7 +1099,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_rayleigh(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.rayleigh(scale=10, size=(3, 2))
desired = np.array([[13.8882496494248393, 13.383318339044731],
[20.95413364294492098, 21.08285015800712614],
@@ -1178,7 +1111,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.rayleigh, scale=-0.)
def test_standard_cauchy(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_cauchy(size=(3, 2))
desired = np.array([[31.87809592667601, 0.349332782046838],
[2.816995747731641, 10.552372563459114],
@@ -1186,7 +1119,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_standard_exponential(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_exponential(size=(3, 2), method='inv')
desired = np.array([[0.96441739162374596, 0.89556604882105506],
[2.1953785836319808, 2.22243285392490542],
@@ -1197,7 +1130,7 @@ class TestRandomDist(object):
assert_raises(TypeError, random.standard_exponential, dtype=np.int32)
def test_standard_gamma(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_gamma(shape=3, size=(3, 2))
desired = np.array([[2.28483515569645, 3.29899524967824],
[11.12492298902645, 2.16784417297277],
@@ -1205,13 +1138,13 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=14)
def test_standard_gammma_scalar_float(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_gamma(3, dtype=np.float32)
desired = 1.3877466
assert_array_almost_equal(actual, desired, decimal=6)
def test_standard_gamma_float(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_gamma(shape=3, size=(3, 2))
desired = np.array([[2.2848352, 3.2989952],
[11.124923, 2.1678442],
@@ -1220,14 +1153,14 @@ class TestRandomDist(object):
def test_standard_gammma_float_out(self):
actual = np.zeros((3, 2), dtype=np.float32)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
random.standard_gamma(10.0, out=actual, dtype=np.float32)
desired = np.array([[6.9824033, 7.3731737],
[14.860578, 7.5327270],
[11.767487, 6.2320185]], dtype=np.float32)
assert_array_almost_equal(actual, desired, decimal=5)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
random.standard_gamma(10.0, out=actual, size=(3, 2), dtype=np.float32)
assert_array_almost_equal(actual, desired, decimal=5)
@@ -1247,7 +1180,7 @@ class TestRandomDist(object):
assert_raises(ValueError, random.standard_gamma, shape=-0.)
def test_standard_normal(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_normal(size=(3, 2))
desired = np.array([[-3.472754000610961, -0.108938564229143],
[-0.245965753396411, -0.704101550261701],
@@ -1258,7 +1191,7 @@ class TestRandomDist(object):
assert_raises(TypeError, random.standard_normal, dtype=np.int32)
def test_standard_t(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.standard_t(df=10, size=(3, 2))
desired = np.array([[-3.68722108185508, -0.672031186266171],
[2.900224996448669, -0.199656996187739],
@@ -1266,7 +1199,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_triangular(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.triangular(left=5.12, mode=10.23, right=20.34,
size=(3, 2))
desired = np.array([[12.68117178949215784, 12.4129206149193152],
@@ -1275,7 +1208,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=14)
def test_uniform(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.uniform(low=1.23, high=10.54, size=(3, 2))
desired = np.array([[6.99097932346268003, 6.73801597444323974],
[9.50364421400426274, 9.53130618907631089],
@@ -1321,7 +1254,7 @@ class TestRandomDist(object):
assert_raises(TypeError, random.hypergeometric, throwing_int, 1, 1)
def test_vonmises(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.vonmises(mu=1.23, kappa=1.54, size=(3, 2))
desired = np.array([[2.28567572673902042, 2.89163838442285037],
[0.38198375564286025, 2.57638023113890746],
@@ -1330,17 +1263,17 @@ class TestRandomDist(object):
def test_vonmises_small(self):
# check infinite loop, gh-4720
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
r = random.vonmises(mu=0., kappa=1.1e-8, size=10**6)
assert_(np.isfinite(r).all())
def test_vonmises_nan(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
r = random.vonmises(mu=0., kappa=np.nan)
assert_(np.isnan(r))
def test_wald(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.wald(mean=1.23, scale=1.54, size=(3, 2))
desired = np.array([[0.10653278160339, 0.98771068102461],
[0.89276055317879, 0.13640126419923],
@@ -1348,7 +1281,7 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=14)
def test_weibull(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.weibull(a=1.23, size=(3, 2))
desired = np.array([[3.557276979846361, 1.020870580998542],
[2.731847777612348, 1.29148068905082],
@@ -1356,12 +1289,12 @@ class TestRandomDist(object):
assert_array_almost_equal(actual, desired, decimal=15)
def test_weibull_0(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
assert_equal(random.weibull(a=0, size=12), np.zeros(12))
assert_raises(ValueError, random.weibull, a=-0.)
def test_zipf(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.zipf(a=1.23, size=(3, 2))
desired = np.array([[66, 29],
[1, 1],
@@ -1376,7 +1309,7 @@ class TestBroadcast(object):
self.seed = 123456789
def set_seed(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
def test_uniform(self):
low = [0]
@@ -1956,7 +1889,7 @@ class TestBroadcast(object):
assert_raises(ValueError, logseries, bad_p_two * 3)
def test_multinomial(self):
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.multinomial([5, 20], [1 / 6.] * 6, size=(3, 2))
desired = np.array([[[1, 1, 1, 1, 0, 1],
[4, 5, 1, 4, 3, 3]],
@@ -1966,7 +1899,7 @@ class TestBroadcast(object):
[3, 2, 3, 4, 2, 6]]], dtype=np.int64)
assert_array_equal(actual, desired)
- random.brng.seed(self.seed)
+ random.bit_generator.seed(self.seed)
actual = random.multinomial([5, 20], [1 / 6.] * 6)
desired = np.array([[1, 1, 1, 1, 0, 1],
[4, 5, 1, 4, 3, 3]], dtype=np.int64)
@@ -1985,14 +1918,14 @@ class TestThread(object):
out2 = np.empty((len(self.seeds),) + sz)
# threaded generation
- t = [Thread(target=function, args=(RandomGenerator(MT19937(s)), o))
+ t = [Thread(target=function, args=(Generator(MT19937(s)), o))
for s, o in zip(self.seeds, out1)]
[x.start() for x in t]
[x.join() for x in t]
# the same serial
for s, o in zip(self.seeds, out2):
- function(RandomGenerator(MT19937(s)), o)
+ function(Generator(MT19937(s)), o)
# these platforms change x87 fpu precision mode in threads
if np.intp().dtype.itemsize == 4 and sys.platform == "win32":
@@ -2073,21 +2006,21 @@ class TestSingleEltArrayInput(object):
out = func(self.argOne, argTwo[0])
assert_equal(out.shape, self.tgtShape)
- def test_randint(self, closed):
+ def test_integers(self, endpoint):
itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
np.int32, np.uint32, np.int64, np.uint64]
- func = random.randint
+ func = random.integers
high = np.array([1])
low = np.array([0])
for dt in itype:
- out = func(low, high, closed=closed, dtype=dt)
+ out = func(low, high, endpoint=endpoint, dtype=dt)
assert_equal(out.shape, self.tgtShape)
- out = func(low[0], high, closed=closed, dtype=dt)
+ out = func(low[0], high, endpoint=endpoint, dtype=dt)
assert_equal(out.shape, self.tgtShape)
- out = func(low, high[0], closed=closed, dtype=dt)
+ out = func(low, high[0], endpoint=endpoint, dtype=dt)
assert_equal(out.shape, self.tgtShape)
def test_three_arg_funcs(self):
diff --git a/numpy/random/tests/test_generator_mt19937_regressions.py b/numpy/random/tests/test_generator_mt19937_regressions.py
index f9478ccf6..cd4e08d6f 100644
--- a/numpy/random/tests/test_generator_mt19937_regressions.py
+++ b/numpy/random/tests/test_generator_mt19937_regressions.py
@@ -3,9 +3,9 @@ from numpy.testing import (assert_, assert_array_equal)
from numpy.compat import long
import numpy as np
import pytest
-from numpy.random import RandomGenerator, MT19937
+from numpy.random import Generator, MT19937
-mt19937 = RandomGenerator(MT19937())
+mt19937 = Generator(MT19937())
class TestRegression(object):
@@ -36,7 +36,7 @@ class TestRegression(object):
def test_logseries_convergence(self):
# Test for ticket #923
N = 1000
- mt19937.brng.seed(0)
+ mt19937.bit_generator.seed(0)
rvsn = mt19937.logseries(0.8, size=N)
# these two frequency counts should be close to theoretical
# numbers with this large sample
@@ -50,9 +50,9 @@ class TestRegression(object):
assert_(freq < 0.23, msg)
def test_permutation_longs(self):
- mt19937.brng.seed(1234)
+ mt19937.bit_generator.seed(1234)
a = mt19937.permutation(12)
- mt19937.brng.seed(1234)
+ mt19937.bit_generator.seed(1234)
b = mt19937.permutation(long(12))
assert_array_equal(a, b)
@@ -62,18 +62,18 @@ class TestRegression(object):
[(1, 1), (2, 2), (3, 3), None],
[1, (2, 2), (3, 3), None],
[(1, 1), 2, 3, None]]:
- mt19937.brng.seed(12345)
+ mt19937.bit_generator.seed(12345)
shuffled = list(t)
mt19937.shuffle(shuffled)
assert_array_equal(shuffled, [t[0], t[3], t[1], t[2]])
def test_call_within_randomstate(self):
# Check that custom RandomState does not call into global state
- m = RandomGenerator(MT19937()) # mt19937.RandomState()
+ m = Generator(MT19937()) # mt19937.RandomState()
res = np.array([0, 8, 7, 2, 1, 9, 4, 7, 0, 3])
for i in range(3):
- mt19937.brng.seed(i)
- m.brng.seed(4321)
+ mt19937.bit_generator.seed(i)
+ m.bit_generator.seed(4321)
# If m.state is not honored, the result will change
assert_array_equal(m.choice(10, size=10, p=np.ones(10)/10.), res)
@@ -88,7 +88,7 @@ class TestRegression(object):
def test_beta_small_parameters(self):
# Test that beta with small a and b parameters does not produce
# NaNs due to roundoff errors causing 0 / 0, gh-5851
- mt19937.brng.seed(1234567890)
+ mt19937.bit_generator.seed(1234567890)
x = mt19937.beta(0.0001, 0.0001, size=100)
assert_(not np.any(np.isnan(x)), 'Nans in mt19937.beta')
@@ -96,7 +96,7 @@ class TestRegression(object):
# The sum of probs should be 1.0 with some tolerance.
# For low precision dtypes the tolerance was too tight.
# See numpy github issue 6123.
- mt19937.brng.seed(1234)
+ mt19937.bit_generator.seed(1234)
a = [1, 2, 3]
counts = [4, 4, 2]
for dt in np.float16, np.float32, np.float64:
@@ -110,7 +110,7 @@ class TestRegression(object):
# Test that permuting an array of different length strings
# will not cause a segfault on garbage collection
# Tests gh-7710
- mt19937.brng.seed(1234)
+ mt19937.bit_generator.seed(1234)
a = np.array(['a', 'a' * 1000])
@@ -125,7 +125,7 @@ class TestRegression(object):
# Test that permuting an array of objects will not cause
# a segfault on garbage collection.
# See gh-7719
- mt19937.brng.seed(1234)
+ mt19937.bit_generator.seed(1234)
a = np.array([np.arange(1), np.arange(4)])
for _ in range(1000):
@@ -139,7 +139,7 @@ class TestRegression(object):
class N(np.ndarray):
pass
- mt19937.brng.seed(1)
+ mt19937.bit_generator.seed(1)
orig = np.arange(3).view(N)
perm = mt19937.permutation(orig)
assert_array_equal(perm, np.array([0, 2, 1]))
@@ -151,7 +151,7 @@ class TestRegression(object):
def __array__(self):
return self.a
- mt19937.brng.seed(1)
+ mt19937.bit_generator.seed(1)
m = M()
perm = mt19937.permutation(m)
assert_array_equal(perm, np.array([2, 1, 4, 0, 3]))
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 711270072..b367599cd 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -349,9 +349,9 @@ class TestRandomDist(object):
np.random.random_integers,
np.iinfo('l').max, np.iinfo('l').max)
- def test_random_sample(self):
+ def test_random(self):
np.random.seed(self.seed)
- actual = np.random.random_sample((3, 2))
+ actual = np.random.random((3, 2))
desired = np.array([[0.61879477158567997, 0.59162362775974664],
[0.88868358904449662, 0.89165480011560816],
[0.4575674820298663, 0.7781880808593471]])
diff --git a/numpy/random/tests/test_randomstate.py b/numpy/random/tests/test_randomstate.py
index c5fb5c9b4..0c57b9aaf 100644
--- a/numpy/random/tests/test_randomstate.py
+++ b/numpy/random/tests/test_randomstate.py
@@ -9,11 +9,11 @@ from numpy.testing import (
suppress_warnings
)
-from numpy.random import MT19937, Xoshiro256StarStar, mtrand as random
+from numpy.random import MT19937, Xoshiro256, mtrand as random
def assert_mt19937_state_equal(a, b):
- assert_equal(a['brng'], b['brng'])
+ assert_equal(a['bit_generator'], b['bit_generator'])
assert_array_equal(a['state']['key'], b['state']['key'])
assert_array_equal(a['state']['pos'], b['state']['pos'])
assert_equal(a['has_gauss'], b['has_gauss'])
@@ -166,13 +166,13 @@ class TestSetState(object):
self.random_state.negative_binomial(0.5, 0.5)
def test_get_state_warning(self):
- rs = random.RandomState(Xoshiro256StarStar())
+ rs = random.RandomState(Xoshiro256())
with suppress_warnings() as sup:
w = sup.record(RuntimeWarning)
state = rs.get_state()
assert_(len(w) == 1)
assert isinstance(state, dict)
- assert state['brng'] == 'Xoshiro256StarStar'
+ assert state['bit_generator'] == 'Xoshiro256'
def test_invalid_legacy_state_setting(self):
state = self.random_state.get_state()
@@ -181,7 +181,7 @@ class TestSetState(object):
assert_raises(TypeError, self.random_state.set_state,
np.array(new_state, dtype=np.object))
state = self.random_state.get_state(legacy=False)
- del state['brng']
+ del state['bit_generator']
assert_raises(ValueError, self.random_state.set_state, state)
def test_pickle(self):
diff --git a/numpy/random/tests/test_smoke.py b/numpy/random/tests/test_smoke.py
index fa7a0b567..4bfa0ae6e 100644
--- a/numpy/random/tests/test_smoke.py
+++ b/numpy/random/tests/test_smoke.py
@@ -8,9 +8,9 @@ import numpy as np
import pytest
from numpy.testing import (assert_almost_equal, assert_equal, assert_,
assert_array_equal, suppress_warnings)
-from numpy.random import (RandomGenerator, MT19937, DSFMT, ThreeFry32, ThreeFry,
- PCG32, PCG64, Philox, Xoroshiro128, Xorshift1024, Xoshiro256StarStar,
- Xoshiro512StarStar, entropy)
+from numpy.random import (Generator, MT19937, DSFMT, ThreeFry32, ThreeFry,
+ Philox, Xoroshiro128, Xorshift1024, Xoshiro256,
+ Xoshiro512, entropy)
@pytest.fixture(scope='module',
@@ -90,23 +90,23 @@ def warmup(rg, n=None):
rg.standard_normal(n)
rg.standard_normal(n, dtype=np.float32)
rg.standard_normal(n, dtype=np.float32)
- rg.randint(0, 2 ** 24, n, dtype=np.uint64)
- rg.randint(0, 2 ** 48, n, dtype=np.uint64)
+ rg.integers(0, 2 ** 24, n, dtype=np.uint64)
+ rg.integers(0, 2 ** 48, n, dtype=np.uint64)
rg.standard_gamma(11.0, n)
rg.standard_gamma(11.0, n, dtype=np.float32)
- rg.random_sample(n, dtype=np.float64)
- rg.random_sample(n, dtype=np.float32)
+ rg.random(n, dtype=np.float64)
+ rg.random(n, dtype=np.float32)
class RNG(object):
@classmethod
def setup_class(cls):
# Overridden in test classes. Place holder to silence IDE noise
- cls.brng = Xoshiro256StarStar
+ cls.bit_generator = Xoshiro256
cls.advance = None
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
@@ -118,39 +118,41 @@ class RNG(object):
cls.seed_error = TypeError
def _reset_state(self):
- self.rg.brng.state = self.initial_state
+ self.rg.bit_generator.state = self.initial_state
def test_init(self):
- rg = RandomGenerator(self.brng())
- state = rg.brng.state
+ rg = Generator(self.bit_generator())
+ state = rg.bit_generator.state
rg.standard_normal(1)
rg.standard_normal(1)
- rg.brng.state = state
- new_state = rg.brng.state
+ rg.bit_generator.state = state
+ new_state = rg.bit_generator.state
assert_(comp_state(state, new_state))
def test_advance(self):
- state = self.rg.brng.state
- if hasattr(self.rg.brng, 'advance'):
- self.rg.brng.advance(self.advance)
- assert_(not comp_state(state, self.rg.brng.state))
+ state = self.rg.bit_generator.state
+ if hasattr(self.rg.bit_generator, 'advance'):
+ self.rg.bit_generator.advance(self.advance)
+ assert_(not comp_state(state, self.rg.bit_generator.state))
else:
- brng_name = self.rg.brng.__class__.__name__
+ brng_name = self.rg.bit_generator.__class__.__name__
pytest.skip('Advance is not supported by {0}'.format(brng_name))
def test_jump(self):
- state = self.rg.brng.state
- if hasattr(self.rg.brng, 'jump'):
- self.rg.brng.jump()
- jumped_state = self.rg.brng.state
+ state = self.rg.bit_generator.state
+ if hasattr(self.rg.bit_generator, 'jumped'):
+ bit_gen2 = self.rg.bit_generator.jumped()
+ jumped_state = bit_gen2.state
assert_(not comp_state(state, jumped_state))
- self.rg.random_sample(2 * 3 * 5 * 7 * 11 * 13 * 17)
- self.rg.brng.state = state
- self.rg.brng.jump()
- rejumped_state = self.rg.brng.state
+ self.rg.random(2 * 3 * 5 * 7 * 11 * 13 * 17)
+ self.rg.bit_generator.state = state
+ bit_gen3 = self.rg.bit_generator.jumped()
+ rejumped_state = bit_gen3.state
assert_(comp_state(jumped_state, rejumped_state))
else:
- brng_name = self.rg.brng.__class__.__name__
+ brng_name = self.rg.bit_generator.__class__.__name__
+ if name not in ('',):
+ raise AttributeError('no "jumped" in %s' % brng_name)
pytest.skip('Jump is not supported by {0}'.format(brng_name))
def test_uniform(self):
@@ -174,9 +176,9 @@ class RNG(object):
assert_((r > -1).all())
assert_((r <= 0).all())
- def test_random_sample(self):
- assert_(len(self.rg.random_sample(10)) == 10)
- params_0(self.rg.random_sample)
+ def test_random(self):
+ assert_(len(self.rg.random(10)) == 10)
+ params_0(self.rg.random)
def test_standard_normal_zig(self):
assert_(len(self.rg.standard_normal(10)) == 10)
@@ -221,52 +223,52 @@ class RNG(object):
assert_(self.rg.binomial(1000, .5) >= 0)
def test_reset_state(self):
- state = self.rg.brng.state
- int_1 = self.rg.randint(2**31)
- self.rg.brng.state = state
- int_2 = self.rg.randint(2**31)
+ state = self.rg.bit_generator.state
+ int_1 = self.rg.integers(2**31)
+ self.rg.bit_generator.state = state
+ int_2 = self.rg.integers(2**31)
assert_(int_1 == int_2)
def test_entropy_init(self):
- rg = RandomGenerator(self.brng())
- rg2 = RandomGenerator(self.brng())
- assert_(not comp_state(rg.brng.state, rg2.brng.state))
+ rg = Generator(self.bit_generator())
+ rg2 = Generator(self.bit_generator())
+ assert_(not comp_state(rg.bit_generator.state, rg2.bit_generator.state))
def test_seed(self):
- rg = RandomGenerator(self.brng(*self.seed))
- rg2 = RandomGenerator(self.brng(*self.seed))
- rg.random_sample()
- rg2.random_sample()
- assert_(comp_state(rg.brng.state, rg2.brng.state))
+ rg = Generator(self.bit_generator(*self.seed))
+ rg2 = Generator(self.bit_generator(*self.seed))
+ rg.random()
+ rg2.random()
+ assert_(comp_state(rg.bit_generator.state, rg2.bit_generator.state))
def test_reset_state_gauss(self):
- rg = RandomGenerator(self.brng(*self.seed))
+ rg = Generator(self.bit_generator(*self.seed))
rg.standard_normal()
- state = rg.brng.state
+ state = rg.bit_generator.state
n1 = rg.standard_normal(size=10)
- rg2 = RandomGenerator(self.brng())
- rg2.brng.state = state
+ rg2 = Generator(self.bit_generator())
+ rg2.bit_generator.state = state
n2 = rg2.standard_normal(size=10)
assert_array_equal(n1, n2)
def test_reset_state_uint32(self):
- rg = RandomGenerator(self.brng(*self.seed))
- rg.randint(0, 2 ** 24, 120, dtype=np.uint32)
- state = rg.brng.state
- n1 = rg.randint(0, 2 ** 24, 10, dtype=np.uint32)
- rg2 = RandomGenerator(self.brng())
- rg2.brng.state = state
- n2 = rg2.randint(0, 2 ** 24, 10, dtype=np.uint32)
+ rg = Generator(self.bit_generator(*self.seed))
+ rg.integers(0, 2 ** 24, 120, dtype=np.uint32)
+ state = rg.bit_generator.state
+ n1 = rg.integers(0, 2 ** 24, 10, dtype=np.uint32)
+ rg2 = Generator(self.bit_generator())
+ rg2.bit_generator.state = state
+ n2 = rg2.integers(0, 2 ** 24, 10, dtype=np.uint32)
assert_array_equal(n1, n2)
def test_reset_state_float(self):
- rg = RandomGenerator(self.brng(*self.seed))
- rg.random_sample(dtype='float32')
- state = rg.brng.state
- n1 = rg.random_sample(size=10, dtype='float32')
- rg2 = RandomGenerator(self.brng())
- rg2.brng.state = state
- n2 = rg2.random_sample(size=10, dtype='float32')
+ rg = Generator(self.bit_generator(*self.seed))
+ rg.random(dtype='float32')
+ state = rg.bit_generator.state
+ n1 = rg.random(size=10, dtype='float32')
+ rg2 = Generator(self.bit_generator())
+ rg2.bit_generator.state = state
+ n2 = rg2.random(size=10, dtype='float32')
assert_((n1 == n2).all())
def test_shuffle(self):
@@ -353,33 +355,6 @@ class RNG(object):
vals = self.rg.negative_binomial(10, 0.2, 10)
assert_(len(vals) == 10)
- def test_rand(self):
- state = self.rg.brng.state
- vals = self.rg.rand(10, 10, 10)
- self.rg.brng.state = state
- assert_((vals == self.rg.random_sample((10, 10, 10))).all())
- assert_(vals.shape == (10, 10, 10))
- vals = self.rg.rand(10, 10, 10, dtype=np.float32)
- assert_(vals.shape == (10, 10, 10))
-
- def test_randn(self):
- state = self.rg.brng.state
- vals = self.rg.randn(10, 10, 10)
- self.rg.brng.state = state
- assert_equal(vals, self.rg.standard_normal((10, 10, 10)))
- assert_equal(vals.shape, (10, 10, 10))
-
- state = self.rg.brng.state
- vals = self.rg.randn(10, 10, 10)
- self.rg.brng.state = state
- assert_equal(vals, self.rg.standard_normal((10, 10, 10)))
-
- state = self.rg.brng.state
- self.rg.randn(10, 10, 10)
- self.rg.brng.state = state
- vals = self.rg.randn(10, 10, 10, dtype=np.float32)
- assert_(vals.shape == (10, 10, 10))
-
def test_noncentral_chisquare(self):
vals = self.rg.noncentral_chisquare(10, 2, 10)
assert_(len(vals) == 10)
@@ -413,14 +388,8 @@ class RNG(object):
vals = self.rg.power(0.2, 10)
assert_(len(vals) == 10)
- def test_randint(self):
- vals = self.rg.randint(10, 20, 10)
- assert_(len(vals) == 10)
-
- def test_random_integers(self):
- with suppress_warnings() as sup:
- sup.record(DeprecationWarning)
- vals = self.rg.random_integers(10, 20, 10)
+ def test_integers(self):
+ vals = self.rg.integers(10, 20, 10)
assert_(len(vals) == 10)
def test_rayleigh(self):
@@ -487,16 +456,16 @@ class RNG(object):
pick = pickle.dumps(self.rg)
unpick = pickle.loads(pick)
assert_((type(self.rg) == type(unpick)))
- assert_(comp_state(self.rg.brng.state, unpick.brng.state))
+ assert_(comp_state(self.rg.bit_generator.state, unpick.bit_generator.state))
pick = pickle.dumps(self.rg)
unpick = pickle.loads(pick)
assert_((type(self.rg) == type(unpick)))
- assert_(comp_state(self.rg.brng.state, unpick.brng.state))
+ assert_(comp_state(self.rg.bit_generator.state, unpick.bit_generator.state))
def test_seed_array(self):
if self.seed_vector_bits is None:
- brng_name = self.brng.__name__
+ brng_name = self.bit_generator.__name__
pytest.skip('Vector seeding is not supported by '
'{0}'.format(brng_name))
@@ -505,32 +474,32 @@ class RNG(object):
else:
dtype = np.uint64
seed = np.array([1], dtype=dtype)
- self.rg.brng.seed(seed)
- state1 = self.rg.brng.state
- self.rg.brng.seed(1)
- state2 = self.rg.brng.state
+ self.rg.bit_generator.seed(seed)
+ state1 = self.rg.bit_generator.state
+ self.rg.bit_generator.seed(1)
+ state2 = self.rg.bit_generator.state
assert_(comp_state(state1, state2))
seed = np.arange(4, dtype=dtype)
- self.rg.brng.seed(seed)
- state1 = self.rg.brng.state
- self.rg.brng.seed(seed[0])
- state2 = self.rg.brng.state
+ self.rg.bit_generator.seed(seed)
+ state1 = self.rg.bit_generator.state
+ self.rg.bit_generator.seed(seed[0])
+ state2 = self.rg.bit_generator.state
assert_(not comp_state(state1, state2))
seed = np.arange(1500, dtype=dtype)
- self.rg.brng.seed(seed)
- state1 = self.rg.brng.state
- self.rg.brng.seed(seed[0])
- state2 = self.rg.brng.state
+ self.rg.bit_generator.seed(seed)
+ state1 = self.rg.bit_generator.state
+ self.rg.bit_generator.seed(seed[0])
+ state2 = self.rg.bit_generator.state
assert_(not comp_state(state1, state2))
seed = 2 ** np.mod(np.arange(1500, dtype=dtype),
self.seed_vector_bits - 1) + 1
- self.rg.brng.seed(seed)
- state1 = self.rg.brng.state
- self.rg.brng.seed(seed[0])
- state2 = self.rg.brng.state
+ self.rg.bit_generator.seed(seed)
+ state1 = self.rg.bit_generator.state
+ self.rg.bit_generator.seed(seed[0])
+ state2 = self.rg.bit_generator.state
assert_(not comp_state(state1, state2))
def test_seed_array_error(self):
@@ -541,164 +510,164 @@ class RNG(object):
seed = -1
with pytest.raises(ValueError):
- self.rg.brng.seed(seed)
+ self.rg.bit_generator.seed(seed)
seed = np.array([-1], dtype=np.int32)
with pytest.raises(ValueError):
- self.rg.brng.seed(seed)
+ self.rg.bit_generator.seed(seed)
seed = np.array([1, 2, 3, -5], dtype=np.int32)
with pytest.raises(ValueError):
- self.rg.brng.seed(seed)
+ self.rg.bit_generator.seed(seed)
seed = np.array([1, 2, 3, out_of_bounds])
with pytest.raises(ValueError):
- self.rg.brng.seed(seed)
+ self.rg.bit_generator.seed(seed)
def test_uniform_float(self):
- rg = RandomGenerator(self.brng(12345))
+ rg = Generator(self.bit_generator(12345))
warmup(rg)
- state = rg.brng.state
- r1 = rg.random_sample(11, dtype=np.float32)
- rg2 = RandomGenerator(self.brng())
+ state = rg.bit_generator.state
+ r1 = rg.random(11, dtype=np.float32)
+ rg2 = Generator(self.bit_generator())
warmup(rg2)
- rg2.brng.state = state
- r2 = rg2.random_sample(11, dtype=np.float32)
+ rg2.bit_generator.state = state
+ r2 = rg2.random(11, dtype=np.float32)
assert_array_equal(r1, r2)
assert_equal(r1.dtype, np.float32)
- assert_(comp_state(rg.brng.state, rg2.brng.state))
+ assert_(comp_state(rg.bit_generator.state, rg2.bit_generator.state))
def test_gamma_floats(self):
- rg = RandomGenerator(self.brng())
+ rg = Generator(self.bit_generator())
warmup(rg)
- state = rg.brng.state
+ state = rg.bit_generator.state
r1 = rg.standard_gamma(4.0, 11, dtype=np.float32)
- rg2 = RandomGenerator(self.brng())
+ rg2 = Generator(self.bit_generator())
warmup(rg2)
- rg2.brng.state = state
+ rg2.bit_generator.state = state
r2 = rg2.standard_gamma(4.0, 11, dtype=np.float32)
assert_array_equal(r1, r2)
assert_equal(r1.dtype, np.float32)
- assert_(comp_state(rg.brng.state, rg2.brng.state))
+ assert_(comp_state(rg.bit_generator.state, rg2.bit_generator.state))
def test_normal_floats(self):
- rg = RandomGenerator(self.brng())
+ rg = Generator(self.bit_generator())
warmup(rg)
- state = rg.brng.state
+ state = rg.bit_generator.state
r1 = rg.standard_normal(11, dtype=np.float32)
- rg2 = RandomGenerator(self.brng())
+ rg2 = Generator(self.bit_generator())
warmup(rg2)
- rg2.brng.state = state
+ rg2.bit_generator.state = state
r2 = rg2.standard_normal(11, dtype=np.float32)
assert_array_equal(r1, r2)
assert_equal(r1.dtype, np.float32)
- assert_(comp_state(rg.brng.state, rg2.brng.state))
+ assert_(comp_state(rg.bit_generator.state, rg2.bit_generator.state))
def test_normal_zig_floats(self):
- rg = RandomGenerator(self.brng())
+ rg = Generator(self.bit_generator())
warmup(rg)
- state = rg.brng.state
+ state = rg.bit_generator.state
r1 = rg.standard_normal(11, dtype=np.float32)
- rg2 = RandomGenerator(self.brng())
+ rg2 = Generator(self.bit_generator())
warmup(rg2)
- rg2.brng.state = state
+ rg2.bit_generator.state = state
r2 = rg2.standard_normal(11, dtype=np.float32)
assert_array_equal(r1, r2)
assert_equal(r1.dtype, np.float32)
- assert_(comp_state(rg.brng.state, rg2.brng.state))
+ assert_(comp_state(rg.bit_generator.state, rg2.bit_generator.state))
def test_output_fill(self):
rg = self.rg
- state = rg.brng.state
+ state = rg.bit_generator.state
size = (31, 7, 97)
existing = np.empty(size)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_normal(out=existing)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_normal(size=size)
assert_equal(direct, existing)
sized = np.empty(size)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_normal(out=sized, size=sized.shape)
existing = np.empty(size, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_normal(out=existing, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_normal(size=size, dtype=np.float32)
assert_equal(direct, existing)
def test_output_filling_uniform(self):
rg = self.rg
- state = rg.brng.state
+ state = rg.bit_generator.state
size = (31, 7, 97)
existing = np.empty(size)
- rg.brng.state = state
- rg.random_sample(out=existing)
- rg.brng.state = state
- direct = rg.random_sample(size=size)
+ rg.bit_generator.state = state
+ rg.random(out=existing)
+ rg.bit_generator.state = state
+ direct = rg.random(size=size)
assert_equal(direct, existing)
existing = np.empty(size, dtype=np.float32)
- rg.brng.state = state
- rg.random_sample(out=existing, dtype=np.float32)
- rg.brng.state = state
- direct = rg.random_sample(size=size, dtype=np.float32)
+ rg.bit_generator.state = state
+ rg.random(out=existing, dtype=np.float32)
+ rg.bit_generator.state = state
+ direct = rg.random(size=size, dtype=np.float32)
assert_equal(direct, existing)
def test_output_filling_exponential(self):
rg = self.rg
- state = rg.brng.state
+ state = rg.bit_generator.state
size = (31, 7, 97)
existing = np.empty(size)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_exponential(out=existing)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_exponential(size=size)
assert_equal(direct, existing)
existing = np.empty(size, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_exponential(out=existing, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_exponential(size=size, dtype=np.float32)
assert_equal(direct, existing)
def test_output_filling_gamma(self):
rg = self.rg
- state = rg.brng.state
+ state = rg.bit_generator.state
size = (31, 7, 97)
existing = np.zeros(size)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_gamma(1.0, out=existing)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_gamma(1.0, size=size)
assert_equal(direct, existing)
existing = np.zeros(size, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_gamma(1.0, out=existing, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_gamma(1.0, size=size, dtype=np.float32)
assert_equal(direct, existing)
def test_output_filling_gamma_broadcast(self):
rg = self.rg
- state = rg.brng.state
+ state = rg.bit_generator.state
size = (31, 7, 97)
mu = np.arange(97.0) + 1.0
existing = np.zeros(size)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_gamma(mu, out=existing)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_gamma(mu, size=size)
assert_equal(direct, existing)
existing = np.zeros(size, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
rg.standard_gamma(mu, out=existing, dtype=np.float32)
- rg.brng.state = state
+ rg.bit_generator.state = state
direct = rg.standard_gamma(mu, size=size, dtype=np.float32)
assert_equal(direct, existing)
@@ -725,7 +694,7 @@ class RNG(object):
with pytest.raises(ValueError):
rg.standard_gamma(1.0, out=existing[::3])
- def test_randint_broadcast(self, dtype):
+ def test_integers_broadcast(self, dtype):
if dtype == np.bool:
upper = 2
lower = 0
@@ -734,44 +703,44 @@ class RNG(object):
upper = int(info.max) + 1
lower = info.min
self._reset_state()
- a = self.rg.randint(lower, [upper] * 10, dtype=dtype)
+ a = self.rg.integers(lower, [upper] * 10, dtype=dtype)
self._reset_state()
- b = self.rg.randint([lower] * 10, upper, dtype=dtype)
+ b = self.rg.integers([lower] * 10, upper, dtype=dtype)
assert_equal(a, b)
self._reset_state()
- c = self.rg.randint(lower, upper, size=10, dtype=dtype)
+ c = self.rg.integers(lower, upper, size=10, dtype=dtype)
assert_equal(a, c)
self._reset_state()
- d = self.rg.randint(np.array(
+ d = self.rg.integers(np.array(
[lower] * 10), np.array([upper], dtype=np.object), size=10,
dtype=dtype)
assert_equal(a, d)
self._reset_state()
- e = self.rg.randint(
+ e = self.rg.integers(
np.array([lower] * 10), np.array([upper] * 10), size=10,
dtype=dtype)
assert_equal(a, e)
self._reset_state()
- a = self.rg.randint(0, upper, size=10, dtype=dtype)
+ a = self.rg.integers(0, upper, size=10, dtype=dtype)
self._reset_state()
- b = self.rg.randint([upper] * 10, dtype=dtype)
+ b = self.rg.integers([upper] * 10, dtype=dtype)
assert_equal(a, b)
- def test_randint_numpy(self, dtype):
+ def test_integers_numpy(self, dtype):
high = np.array([1])
low = np.array([0])
- out = self.rg.randint(low, high, dtype=dtype)
+ out = self.rg.integers(low, high, dtype=dtype)
assert out.shape == (1,)
- out = self.rg.randint(low[0], high, dtype=dtype)
+ out = self.rg.integers(low[0], high, dtype=dtype)
assert out.shape == (1,)
- out = self.rg.randint(low, high[0], dtype=dtype)
+ out = self.rg.integers(low, high[0], dtype=dtype)
assert out.shape == (1,)
- def test_randint_broadcast_errors(self, dtype):
+ def test_integers_broadcast_errors(self, dtype):
if dtype == np.bool:
upper = 2
lower = 0
@@ -780,23 +749,23 @@ class RNG(object):
upper = int(info.max) + 1
lower = info.min
with pytest.raises(ValueError):
- self.rg.randint(lower, [upper + 1] * 10, dtype=dtype)
+ self.rg.integers(lower, [upper + 1] * 10, dtype=dtype)
with pytest.raises(ValueError):
- self.rg.randint(lower - 1, [upper] * 10, dtype=dtype)
+ self.rg.integers(lower - 1, [upper] * 10, dtype=dtype)
with pytest.raises(ValueError):
- self.rg.randint([lower - 1], [upper] * 10, dtype=dtype)
+ self.rg.integers([lower - 1], [upper] * 10, dtype=dtype)
with pytest.raises(ValueError):
- self.rg.randint([0], [0], dtype=dtype)
+ self.rg.integers([0], [0], dtype=dtype)
class TestMT19937(RNG):
@classmethod
def setup_class(cls):
- cls.brng = MT19937
+ cls.bit_generator = MT19937
cls.advance = None
cls.seed = [2 ** 21 + 2 ** 16 + 2 ** 5 + 1]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 32
cls._extra_setup()
cls.seed_error = ValueError
@@ -805,57 +774,20 @@ class TestMT19937(RNG):
nprg = np.random.RandomState()
nprg.standard_normal(99)
state = nprg.get_state()
- self.rg.brng.state = state
- state2 = self.rg.brng.state
+ self.rg.bit_generator.state = state
+ state2 = self.rg.bit_generator.state
assert_((state[1] == state2['state']['key']).all())
assert_((state[2] == state2['state']['pos']))
-class TestPCG64(RNG):
- @classmethod
- def setup_class(cls):
- cls.brng = PCG64
- cls.advance = 2 ** 96 + 2 ** 48 + 2 ** 21 + 2 ** 16 + 2 ** 5 + 1
- cls.seed = [2 ** 96 + 2 ** 48 + 2 ** 21 + 2 ** 16 + 2 ** 5 + 1,
- 2 ** 21 + 2 ** 16 + 2 ** 5 + 1]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
- cls.seed_vector_bits = None
- cls._extra_setup()
-
- def test_seed_array_error(self):
- # GH #82 for error type changes
- if self.seed_vector_bits == 32:
- out_of_bounds = 2 ** 32
- else:
- out_of_bounds = 2 ** 64
-
- seed = -1
- with pytest.raises(ValueError):
- self.rg.brng.seed(seed)
-
- error_type = ValueError if self.seed_vector_bits else TypeError
- seed = np.array([-1], dtype=np.int32)
- with pytest.raises(error_type):
- self.rg.brng.seed(seed)
-
- seed = np.array([1, 2, 3, -5], dtype=np.int32)
- with pytest.raises(error_type):
- self.rg.brng.seed(seed)
-
- seed = np.array([1, 2, 3, out_of_bounds])
- with pytest.raises(error_type):
- self.rg.brng.seed(seed)
-
-
class TestPhilox(RNG):
@classmethod
def setup_class(cls):
- cls.brng = Philox
+ cls.bit_generator = Philox
cls.advance = 2**63 + 2**31 + 2**15 + 1
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
@@ -863,11 +795,11 @@ class TestPhilox(RNG):
class TestThreeFry(RNG):
@classmethod
def setup_class(cls):
- cls.brng = ThreeFry
+ cls.bit_generator = ThreeFry
cls.advance = 2 ** 63 + 2 ** 31 + 2 ** 15 + 1
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
@@ -875,35 +807,35 @@ class TestThreeFry(RNG):
class TestXoroshiro128(RNG):
@classmethod
def setup_class(cls):
- cls.brng = Xoroshiro128
+ cls.bit_generator = Xoroshiro128
cls.advance = None
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
-class TestXoshiro256StarStar(RNG):
+class TestXoshiro256(RNG):
@classmethod
def setup_class(cls):
- cls.brng = Xoshiro256StarStar
+ cls.bit_generator = Xoshiro256
cls.advance = None
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
-class TestXoshiro512StarStar(RNG):
+class TestXoshiro512(RNG):
@classmethod
def setup_class(cls):
- cls.brng = Xoshiro512StarStar
+ cls.bit_generator = Xoshiro512
cls.advance = None
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
@@ -911,11 +843,11 @@ class TestXoshiro512StarStar(RNG):
class TestXorshift1024(RNG):
@classmethod
def setup_class(cls):
- cls.brng = Xorshift1024
+ cls.bit_generator = Xorshift1024
cls.advance = None
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
@@ -923,11 +855,11 @@ class TestXorshift1024(RNG):
class TestDSFMT(RNG):
@classmethod
def setup_class(cls):
- cls.brng = DSFMT
+ cls.bit_generator = DSFMT
cls.advance = None
cls.seed = [12345]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls._extra_setup()
cls.seed_vector_bits = 32
@@ -935,11 +867,11 @@ class TestDSFMT(RNG):
class TestThreeFry32(RNG):
@classmethod
def setup_class(cls):
- cls.brng = ThreeFry32
+ cls.bit_generator = ThreeFry32
cls.advance = 2**63 + 2**31 + 2**15 + 1
cls.seed = [2 ** 21 + 2 ** 16 + 2 ** 5 + 1]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
+ cls.rg = Generator(cls.bit_generator(*cls.seed))
+ cls.initial_state = cls.rg.bit_generator.state
cls.seed_vector_bits = 64
cls._extra_setup()
cls.seed_error = ValueError
@@ -962,16 +894,3 @@ class TestEntropy(object):
time.sleep(0.1)
e2 = entropy.random_entropy(source='fallback')
assert_((e1 != e2))
-
-
-class TestPCG32(TestPCG64):
- @classmethod
- def setup_class(cls):
- cls.brng = PCG32
- cls.advance = 2 ** 48 + 2 ** 21 + 2 ** 16 + 2 ** 5 + 1
- cls.seed = [2 ** 48 + 2 ** 21 + 2 ** 16 + 2 ** 5 + 1,
- 2 ** 21 + 2 ** 16 + 2 ** 5 + 1]
- cls.rg = RandomGenerator(cls.brng(*cls.seed))
- cls.initial_state = cls.rg.brng.state
- cls.seed_vector_bits = None
- cls._extra_setup()
diff --git a/numpy/random/threefry.pyx b/numpy/random/threefry.pyx
index a8878c6bc..d008cd828 100644
--- a/numpy/random/threefry.pyx
+++ b/numpy/random/threefry.pyx
@@ -1,4 +1,3 @@
-from libc.stdlib cimport malloc, free
from cpython.pycapsule cimport PyCapsule_New
try:
@@ -9,7 +8,7 @@ except ImportError:
import numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
np.import_array()
@@ -67,56 +66,29 @@ cdef class ThreeFry:
used.
counter : {None, int, array_like}, optional
Counter to use in the ThreeFry state. Can be either
- a Python int (long in 2.x) in [0, 2**256) or a 4-element uint64 array.
+ a Python int in [0, 2**256) or a 4-element uint64 array.
If not provided, the RNG is initialized at 0.
key : {None, int, array_like}, optional
Key to use in the ThreeFry state. Unlike seed, which is run through
another RNG before use, the value in key is directly set. Can be either
- a Python int (long in 2.x) in [0, 2**256) or a 4-element uint64 array.
+ a Python int in [0, 2**256) or a 4-element uint64 array.
key and seed cannot both be used.
Notes
-----
- ThreeFry is a 64-bit PRNG that uses a counter-based design based on weaker
- (and faster) versions of cryptographic functions [1]_. Instances using
- different values of the key produce independent sequences. ThreeFry has a
- period of :math:`2^{256} - 1` and supports arbitrary advancing and jumping
- the sequence in increments of :math:`2^{128}`. These features allow
+ ThreeFry is a 64-bit PRNG that uses a counter-based design based on
+ weaker (and faster) versions of cryptographic functions [1]_. Instances
+ using different values of the key produce independent sequences. ``ThreeFry``
+ has a period of :math:`2^{256} - 1` and supports arbitrary advancing and
+ jumping the sequence in increments of :math:`2^{128}`. These features allow
multiple non-overlapping sequences to be generated.
- ``ThreeFry`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
+ ``ThreeFry`` provides a capsule containing function pointers that produce
+ doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
- **Compatibility Guarantee**
-
- ``ThreeFry`` guarantees that a fixed seed will always produce the
- same results.
-
- See ``Philox`` for a closely related PRNG implementation.
-
- **Parallel Features**
-
- ``ThreeFry`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{128}` random numbers have been generated. Alternatively,
- ``advance`` can be used to advance the counter for an any
- positive step in [0, 2**256). When using ``jump``, all generators should
- be initialized with the same seed to ensure that the segments come from
- the same sequence. Alternatively, ``ThreeFry`` can be used
- in parallel applications by using a sequence of distinct keys where each
- instance uses different key.
-
- >>> from numpy.random import RandomGenerator, ThreeFry
- >>> rg = [RandomGenerator(ThreeFry(1234)) for _ in range(10)]
- # Advance each ThreeFry instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
-
- Using distinct keys produces independent streams
-
- >>> key = 2**196 + 2**132 + 2**65 + 2**33 + 2**17 + 2**9
- >>> rg = [RandomGenerator(ThreeFry(key=key+i)) for i in range(10)]
+ See ``Philox`` for a closely related PRNG.
**State and Seeding**
@@ -127,26 +99,44 @@ cdef class ThreeFry:
sequences.
``ThreeFry`` is seeded using either a single 64-bit unsigned integer
- or a vector of 64-bit unsigned integers. In either case, the input seed is
- used as an input (or inputs) for another simple random number generator,
- Splitmix64, and the output of this PRNG function is used as the initial state.
+ or a vector of 64-bit unsigned integers. In either case, the seed is
+ used as an input for a second random number generator,
+ SplitMix64, and the output of this PRNG function is used as the initial state.
Using a single 64-bit value for the seed can only initialize a small range of
- the possible initial state values. When using an array, the SplitMix64 state
- for producing the ith component of the initial state is XORd with the ith
- value of the seed array until the seed array is exhausted. When using an array
- the initial state for the SplitMix64 state is 0 so that using a single element
- array and using the same value as a scalar will produce the same initial state.
+ the possible initial state values.
- Examples
- --------
- >>> from numpy.random import RandomGenerator, ThreeFry
- >>> rg = RandomGenerator(ThreeFry(1234))
- >>> rg.standard_normal()
- 0.123 # random
+ **Parallel Features**
- Identical method using only ThreeFry
+ ``ThreeFry`` can be used in parallel applications by calling the ``jumped``
+ method to advances the state as-if :math:`2^{128}` random numbers have
+ been generated. Alternatively, ``advance`` can be used to advance the
+ counter for any positive step in [0, 2**256). When using ``jumped``, all
+ generators should be chained to ensure that the segments come from the same
+ sequence.
- >>> rg = ThreeFry(1234).generator
+ >>> from numpy.random import Generator, ThreeFry
+ >>> bit_generator = ThreeFry(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
+
+ Alternatively, ``ThreeFry`` can be used in parallel applications by using
+ a sequence of distinct keys where each instance uses different key.
+
+ >>> key = 2**196 + 2**132 + 2**65 + 2**33 + 2**17 + 2**9
+ >>> rg = [Generator(ThreeFry(key=key+i)) for i in range(10)]
+
+ **Compatibility Guarantee**
+
+ ``ThreeFry`` makes a guarantee that a fixed seed and will always produce
+ the same random integer stream.
+
+ Examples
+ --------
+ >>> from numpy.random import Generator, ThreeFry
+ >>> rg = Generator(ThreeFry(1234))
>>> rg.standard_normal()
0.123 # random
@@ -157,34 +147,32 @@ cdef class ThreeFry:
the International Conference for High Performance Computing,
Networking, Storage and Analysis (SC11), New York, NY: ACM, 2011.
"""
- cdef threefry_state *rng_state
- cdef brng_t *_brng
+ cdef threefry_state rng_state
+ cdef threefry4x64_ctr_t threefry_ctr
+ cdef threefry4x64_key_t threefry_key
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None, counter=None, key=None):
- self.rng_state = <threefry_state *>malloc(sizeof(threefry_state))
- self.rng_state.ctr = <threefry4x64_ctr_t *>malloc(sizeof(threefry4x64_ctr_t))
- self.rng_state.key = <threefry4x64_key_t *>malloc(sizeof(threefry4x64_key_t))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
+ self.rng_state.ctr = &self.threefry_ctr
+ self.rng_state.key = &self.threefry_key
self.seed(seed, counter, key)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &threefry_uint64
- self._brng.next_uint32 = &threefry_uint32
- self._brng.next_double = &threefry_double
- self._brng.next_raw = &threefry_uint64
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &threefry_uint64
+ self._bitgen.next_uint32 = &threefry_uint32
+ self._bitgen.next_double = &threefry_double
+ self._bitgen.next_raw = &threefry_uint64
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = 'BasicRNG'
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
+ cdef const char *name = 'BitGenerator'
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -194,18 +182,8 @@ cdef class ThreeFry:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state.ctr)
- free(self.rng_state.key)
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.has_uint32 = 0
@@ -218,7 +196,7 @@ cdef class ThreeFry:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -243,10 +221,10 @@ cdef class ThreeFry:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None, counter=None, key=None):
"""
@@ -325,7 +303,7 @@ cdef class ThreeFry:
for i in range(THREEFRY_BUFFER_SIZE):
buffer[i] = self.rng_state.buffer[i]
state = {'counter': ctr, 'key': key}
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
'state': state,
'buffer': buffer,
'buffer_pos': self.rng_state.buffer_pos,
@@ -336,8 +314,8 @@ cdef class ThreeFry:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
for i in range(4):
@@ -349,28 +327,45 @@ cdef class ThreeFry:
self.rng_state.uinteger = value['uinteger']
self.rng_state.buffer_pos = value['buffer_pos']
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**128 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
+ """
+ self.advance(iter * 2 ** 128)
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(128 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
Returns
-------
- self : ThreeFry
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is
- required to ensure exact reproducibility.
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
"""
- return self.advance(iter * 2**128)
+ cdef ThreeFry bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
def advance(self, delta):
"""
@@ -410,8 +405,7 @@ cdef class ThreeFry:
"""
cdef np.ndarray delta_a
delta_a = int_to_array(delta, 'step', 256, 64)
- loc = 0
- threefry_advance(<uint64_t *>delta_a.data, self.rng_state)
+ threefry_advance(<uint64_t *>delta_a.data, &self.rng_state)
self._reset_state_variables()
return self
@@ -430,10 +424,10 @@ cdef class ThreeFry:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the BitGenerator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -452,24 +446,9 @@ cdef class ThreeFry:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the BitGenerator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the core PRNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/threefry32.pyx b/numpy/random/threefry32.pyx
index b1b4d4c51..2e2b32bfe 100644
--- a/numpy/random/threefry32.pyx
+++ b/numpy/random/threefry32.pyx
@@ -8,7 +8,7 @@ from cpython.pycapsule cimport PyCapsule_New
from libc.stdlib cimport malloc, free
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
np.import_array()
@@ -51,7 +51,6 @@ cdef double threefry32_double(void* st) nogil:
cdef uint64_t threefry32_raw(void *st) nogil:
return <uint64_t>threefry32_next32(<threefry32_state *> st)
-
cdef class ThreeFry32:
"""
ThreeFry32(seed=None, counter=None, key=None)
@@ -69,57 +68,30 @@ cdef class ThreeFry32:
used.
counter : {None, int, array_like}, optional
Counter to use in the ThreeFry32 state. Can be either
- a Python int (long in 2.x) in [0, 2**128) or a 4-element uint32 array.
+ a Python int in [0, 2**128) or a 4-element uint32 array.
If not provided, the RNG is initialized at 0.
key : {None, int, array_like}, optional
Key to use in the ThreeFry32 state. Unlike seed, which is run through
another RNG before use, the value in key is directly set. Can be either
- a Python int (long in 2.x) in [0, 2**128) or a 4-element uint32 array.
+ a Python int in [0, 2**128) or a 4-element uint32 array.
key and seed cannot both be used.
Notes
-----
ThreeFry32 is a 32-bit PRNG that uses a counter-based design based on
weaker (and faster) versions of cryptographic functions [1]_. Instances
- using different values of the key produce independent sequences. ThreeFry32
+ using different values of the key produce independent sequences. ``ThreeFry32``
has a period of :math:`2^{128} - 1` and supports arbitrary advancing and
jumping the sequence in increments of :math:`2^{64}`. These features allow
multiple non-overlapping sequences to be generated.
- ``ThreeFry32`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
-
- **Compatibility Guarantee**
-
- ``ThreeFry32`` guarantees that a fixed seed will always produce the
- same results.
+ ``ThreeFry32`` provides a capsule containing function pointers that produce
+ doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
See ``TheeFry`` and ``Philox`` closely related PRNG implementations.
- **Parallel Features**
-
- ``ThreeFry32`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{64}` random numbers have been generated. Alternatively,
- ``advance`` can be used to advance the counter for an arbitrary number of
- positive steps in [0, 2**128). When using ``jump``, all generators should
- be initialized with the same seed to ensure that the segments come from
- the same sequence. Alternatively, ``ThreeFry32`` can be used
- in parallel applications by using a sequence of distinct keys where each
- instance uses different key.
-
- >>> from numpy.random import RandomGenerator, ThreeFry32
- >>> rg = [RandomGenerator(ThreeFry32(1234)) for _ in range(10)]
- # Advance each ThreeFry32 instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
-
- Using distinct keys produces independent streams
-
- >>> key = 2**65 + 2**33 + 2**17 + 2**9
- >>> rg = [RandomGenerator(ThreeFry32(key=key+i)) for i in range(10)]
-
**State and Seeding**
The ``ThreeFry32`` state vector consists of a 2 128-bit values encoded as
@@ -130,8 +102,8 @@ cdef class ThreeFry32:
``ThreeFry32`` is seeded using either a single 64-bit unsigned integer
or a vector of 64-bit unsigned integers. In either case, the input seed is
- used as an input (or inputs) for another simple random number generator,
- Splitmix64, and the output of this PRNG function is used as the initial
+ used as an input (or inputs) for a second random number generator,
+ SplitMix64, and the output of this PRNG function is used as the initial
state. Using a single 64-bit value for the seed can only initialize a small
range of the possible initial state values. When using an array, the
SplitMix64 state for producing the ith component of the initial state is
@@ -140,16 +112,38 @@ cdef class ThreeFry32:
is 0 so that using a single element array and using the same value as a
scalar will produce the same initial state.
- Examples
- --------
- >>> from numpy.random import RandomGenerator, ThreeFry32
- >>> rg = RandomGenerator(ThreeFry32(1234))
- >>> rg.standard_normal()
- 0.123 # random
+ **Parallel Features**
+
+ ``ThreeFry32`` can be used in parallel applications by calling the
+ ``jumped`` method to advances the state as-if :math:`2^{64}` random
+ numbers have been generated. Alternatively, ``advance`` can be used to
+ advance the counter for any positive step in [0, 2**128). When using
+ ``jumped``, all generators should be chained to ensure that the segments
+ come from the same sequence.
+
+ >>> from numpy.random import Generator, ThreeFry32
+ >>> bit_generator = ThreeFry32(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
- Identical method using only ThreeFry32
+ Alternatively, ``ThreeFry32`` can be used in parallel applications by using
+ a sequence of distinct keys where each instance uses different key.
- >>> rg = ThreeFry32(1234).generator
+ >>> key = 2**65 + 2**33 + 2**17 + 2**9
+ >>> rg = [Generator(ThreeFry32(key=key+i)) for i in range(10)]
+
+ **Compatibility Guarantee**
+
+ ``ThreeFry32`` makes a guarantee that a fixed seed and will always produce
+ the same random integer stream.
+
+ Examples
+ --------
+ >>> from numpy.random import Generator, ThreeFry32
+ >>> rg = Generator(ThreeFry32(1234))
>>> rg.standard_normal()
0.123 # random
@@ -160,34 +154,32 @@ cdef class ThreeFry32:
the International Conference for High Performance Computing,
Networking, Storage and Analysis (SC11), New York, NY: ACM, 2011.
"""
- cdef threefry32_state *rng_state
- cdef brng_t *_brng
+ cdef threefry32_state rng_state
+ cdef threefry4x32_ctr_t threefry_ctr
+ cdef threefry4x32_key_t threefry_key
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None, counter=None, key=None):
- self.rng_state = <threefry32_state *> malloc(sizeof(threefry32_state))
- self.rng_state.ctr = <threefry4x32_ctr_t *> malloc(sizeof(threefry4x32_ctr_t))
- self.rng_state.key = <threefry4x32_key_t *> malloc(sizeof(threefry4x32_key_t))
- self._brng = <brng_t *> malloc(sizeof(brng_t))
+ self.rng_state.ctr = &self.threefry_ctr
+ self.rng_state.key = &self.threefry_key
self.seed(seed, counter, key)
self.lock = Lock()
- self._brng.state = <void *> self.rng_state
- self._brng.next_uint64 = &threefry32_uint64
- self._brng.next_uint32 = &threefry32_uint32
- self._brng.next_double = &threefry32_double
- self._brng.next_raw = &threefry32_raw
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &threefry32_uint64
+ self._bitgen.next_uint32 = &threefry32_uint32
+ self._bitgen.next_double = &threefry32_double
+ self._bitgen.next_raw = &threefry32_raw
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = 'BasicRNG'
- self.capsule = PyCapsule_New(<void *> self._brng, name, NULL)
+ cdef const char *name = 'BitGenerator'
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -197,18 +189,8 @@ cdef class ThreeFry32:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state.ctr)
- free(self.rng_state.key)
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.buffer_pos = THREEFRY_BUFFER_SIZE
@@ -219,7 +201,7 @@ cdef class ThreeFry32:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -244,10 +226,10 @@ cdef class ThreeFry32:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None, counter=None, key=None):
"""
@@ -325,7 +307,7 @@ cdef class ThreeFry32:
for i in range(THREEFRY_BUFFER_SIZE):
buffer[i] = self.rng_state.buffer[i]
state = {'counter': ctr, 'key': key}
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
'state': state,
'buffer': buffer,
'buffer_pos': self.rng_state.buffer_pos}
@@ -334,8 +316,8 @@ cdef class ThreeFry32:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
for i in range(4):
@@ -345,28 +327,45 @@ cdef class ThreeFry32:
self.rng_state.buffer[i] = <uint32_t> value['buffer'][i]
self.rng_state.buffer_pos = value['buffer_pos']
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**64 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
+ """
+ self.advance(iter * 2 ** 64)
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(64 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
Returns
-------
- self : ThreeFry32
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is
- required to ensure exact reproducibility.
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
"""
- return self.advance(iter * 2 ** 64)
+ cdef ThreeFry32 bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
def advance(self, delta):
"""
@@ -406,8 +405,7 @@ cdef class ThreeFry32:
"""
cdef np.ndarray delta_a
delta_a = int_to_array(delta, 'step', 128, 32)
- loc = 0
- threefry32_advance(<uint32_t *> delta_a.data, self.rng_state)
+ threefry32_advance(<uint32_t *> delta_a.data, &self.rng_state)
self._reset_state_variables()
return self
@@ -426,10 +424,10 @@ cdef class ThreeFry32:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the BitGenerator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -448,24 +446,9 @@ cdef class ThreeFry32:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the BitGenerator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the core PRNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/xoroshiro128.pyx b/numpy/random/xoroshiro128.pyx
index 5c4642513..5d4fda90a 100644
--- a/numpy/random/xoroshiro128.pyx
+++ b/numpy/random/xoroshiro128.pyx
@@ -3,14 +3,14 @@ try:
except ImportError:
from dummy_threading import Lock
-from libc.stdlib cimport malloc, free
+from libc.string cimport memcpy
from cpython.pycapsule cimport PyCapsule_New
import numpy as np
cimport numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
np.import_array()
@@ -47,75 +47,67 @@ cdef class Xoroshiro128:
----------
seed : {None, int, array_like}, optional
Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**64-1], array of integers in
- [0, 2**64-1] or ``None`` (the default). If `seed` is ``None``,
- then ``Xoroshiro128`` will try to read data from
- ``/dev/urandom`` (or the Windows analog) if available. If
- unavailable, a 64-bit hash of the time and process ID is used.
+ Can be an integer in [0, 2**64-1], array of integers in [0, 2**64-1]
+ or ``None`` (the default). If `seed` is ``None``, then data is read
+ from ``/dev/urandom`` (or the Windows analog) if available. If
+ unavailable, a hash of the time and process ID is used.
Notes
-----
- xoroshiro128+ is the successor to xorshift128+ written by David Blackman and
- Sebastiano Vigna. It is a 64-bit PRNG that uses a carefully handcrafted
- shift/rotate-based linear transformation. This change both improves speed and
- statistical quality of the PRNG [1]_. xoroshiro128+ has a period of
- :math:`2^{128} - 1` and supports jumping the sequence in increments of
- :math:`2^{64}`, which allows multiple non-overlapping sequences to be
- generated.
-
- ``Xoroshiro128`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
+ xoroshiro128+ is the successor to xorshift128+ written by David Blackman
+ and Sebastiano Vigna. It is a 64-bit PRNG that uses a carefully
+ handcrafted shift/rotate-based linear transformation. This change both
+ improves speed and statistical quality of the PRNG [1]_. xoroshiro128+ has
+ a period of :math:`2^{128} - 1` and supports jumping the sequence in
+ increments of :math:`2^{64}`, which allows multiple non-overlapping
+ sequences to be generated.
+
+ ``Xoroshiro128`` provides a capsule containing function pointers that produce
+ doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
+
+ See ``Xorshift1024`` for a related PRNG with a larger
+ period (:math:`2^{1024} - 1`) and jumped size (:math:`2^{512} - 1`).
- **Compatibility Guarantee**
+ **State and Seeding**
- ``Xoroshiro128`` guarantees that a fixed seed will always produce the
- same results.
+ The ``Xoroshiro128`` state vector consists of a 2-element array of 64-bit
+ unsigned integers.
- See ``Xorshift1024`` for an related PRNG implementation with a larger
- period (:math:`2^{1024} - 1`) and jump size (:math:`2^{512} - 1`).
+ ``Xoroshiro128`` is seeded using either a single 64-bit unsigned integer
+ or a vector of 64-bit unsigned integers. In either case, the seed is
+ used as an input for another simple random number generator,
+ SplitMix64, and the output of this PRNG function is used as the initial state.
+ Using a single 64-bit value for the seed can only initialize a small range of
+ the possible initial state values.
**Parallel Features**
- ``Xoroshiro128`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{64}` random numbers have been generated. This
- allow the original sequence to be split so that distinct segments can be used
- in each worker process. All generators should be initialized with the same
- seed to ensure that the segments come from the same sequence.
-
- >>> from numpy.random import RandomGenerator, Xoroshiro128
- >>> rg = [RandomGenerator(Xoroshiro128(1234)) for _ in range(10)]
- # Advance each Xoroshiro128 instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
+ ``Xoroshiro128`` can be used in parallel applications by calling the method
+ ``jumped`` which advances the state as-if :math:`2^{64}` random numbers
+ have been generated. This allows the original sequence to be split
+ so that distinct segments can be used in each worker process. All
+ generators should be chained to ensure that the segments come from the same
+ sequence.
+
+ >>> from numpy.random import Generator, Xoroshiro128
+ >>> bit_generator = Xoroshiro128(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
- **State and Seeding**
+ **Compatibility Guarantee**
- The ``Xoroshiro128`` state vector consists of a 2 element array
- of 64-bit unsigned integers.
-
- ``Xoroshiro128`` is seeded using either a single 64-bit unsigned integer
- or a vector of 64-bit unsigned integers. In either case, the input seed is
- used as an input (or inputs) for another simple random number generator,
- Splitmix64, and the output of this PRNG function is used as the initial state.
- Using a single 64-bit value for the seed can only initialize a small range of
- the possible initial state values. When using an array, the SplitMix64 state
- for producing the ith component of the initial state is XORd with the ith
- value of the seed array until the seed array is exhausted. When using an array
- the initial state for the SplitMix64 state is 0 so that using a single element
- array and using the same value as a scalar will produce the same initial state.
+ ``Xoroshiro128`` makes a guarantee that a fixed seed will always
+ produce the same random integer stream.
Examples
--------
- >>> from numpy.random import RandomGenerator, Xoroshiro128
- >>> rg = RandomGenerator(Xoroshiro128(1234))
- >>> rg.standard_normal()
- 0.123 # random
-
- Identical method using only Xoroshiro128
-
- >>> rg = Xoroshiro128(1234).generator
+ >>> from numpy.random import Generator, Xoroshiro128
+ >>> rg = Generator(Xoroshiro128(1234))
>>> rg.standard_normal()
0.123 # random
@@ -124,32 +116,28 @@ cdef class Xoroshiro128:
.. [1] "xoroshiro+ / xorshift* / xorshift+ generators and the PRNG shootout",
http://xorshift.di.unimi.it/
"""
- cdef xoroshiro128_state *rng_state
- cdef brng_t *_brng
+ cdef xoroshiro128_state rng_state
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None):
- self.rng_state = <xoroshiro128_state *>malloc(sizeof(xoroshiro128_state))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
self.seed(seed)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &xoroshiro128_uint64
- self._brng.next_uint32 = &xoroshiro128_uint32
- self._brng.next_double = &xoroshiro128_double
- self._brng.next_raw = &xoroshiro128_uint64
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &xoroshiro128_uint64
+ self._bitgen.next_uint32 = &xoroshiro128_uint32
+ self._bitgen.next_double = &xoroshiro128_double
+ self._bitgen.next_raw = &xoroshiro128_uint64
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
+ cdef const char *name = "BitGenerator"
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -159,16 +147,8 @@ cdef class Xoroshiro128:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.has_uint32 = 0
@@ -178,7 +158,7 @@ cdef class Xoroshiro128:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -203,10 +183,10 @@ cdef class Xoroshiro128:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None):
"""
@@ -241,32 +221,48 @@ cdef class Xoroshiro128:
self.rng_state.s[1] = <uint64_t>int(state[1])
self._reset_state_variables()
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**64 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
-
- Returns
- -------
- self : Xoroshiro128
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is required
- to ensure exact reproducibility.
"""
cdef np.npy_intp i
for i in range(iter):
- xoroshiro128_jump(self.rng_state)
+ xoroshiro128_jump(&self.rng_state)
self._reset_state_variables()
- return self
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(64 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
+
+ Returns
+ -------
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
+ """
+ cdef Xoroshiro128 bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
@property
def state(self):
@@ -282,7 +278,7 @@ cdef class Xoroshiro128:
state = np.empty(2, dtype=np.uint64)
state[0] = self.rng_state.s[0]
state[1] = self.rng_state.s[1]
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
's': state,
'has_uint32': self.rng_state.has_uint32,
'uinteger': self.rng_state.uinteger}
@@ -291,8 +287,8 @@ cdef class Xoroshiro128:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
self.rng_state.s[0] = <uint64_t>value['s'][0]
@@ -315,11 +311,11 @@ cdef class Xoroshiro128:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -338,24 +334,9 @@ cdef class Xoroshiro128:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the basic RNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/xorshift1024.pyx b/numpy/random/xorshift1024.pyx
index 04fb542c1..ad7debe30 100644
--- a/numpy/random/xorshift1024.pyx
+++ b/numpy/random/xorshift1024.pyx
@@ -3,14 +3,14 @@ try:
except ImportError:
from dummy_threading import Lock
-from libc.stdlib cimport malloc, free
+from libc.string cimport memcpy
from cpython.pycapsule cimport PyCapsule_New
import numpy as np
cimport numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
np.import_array()
@@ -44,77 +44,68 @@ cdef class Xorshift1024:
Container for the xorshift1024*φ pseudo-random number generator.
+ Parameters
+ ----------
+ seed : {None, int, array_like}, optional
+ Random seed initializing the pseudo-random number generator.
+ Can be an integer in [0, 2**64-1], array of integers in [0, 2**64-1]
+ or ``None`` (the default). If `seed` is ``None``, then data is read
+ from ``/dev/urandom`` (or the Windows analog) if available. If
+ unavailable, a hash of the time and process ID is used.
+
+ Notes
+ -----
xorshift1024*φ is a 64-bit implementation of Saito and Matsumoto's XSadd
generator [1]_ (see also [2]_, [3]_, [4]_). xorshift1024*φ has a period of
:math:`2^{1024} - 1` and supports jumping the sequence in increments of
:math:`2^{512}`, which allows multiple non-overlapping sequences to be
generated.
- ``Xorshift1024`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
+ ``Xorshift1024`` provides a capsule containing function pointers that
+ produce doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
- **Compatibility Guarantee**
+ See ``Xoroshiro128`` for a faster bit generator that has a smaller period.
- ``Xorshift1024`` guarantees that a fixed seed will always produce the
- same results.
+ **State and Seeding**
- Parameters
- ----------
- seed : {None, int, array_like}, optional
- Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**64-1], array of integers in
- [0, 2**64-1] or ``None`` (the default). If `seed` is ``None``,
- then ``Xorshift1024`` will try to read data from
- ``/dev/urandom`` (or the Windows analog) if available. If
- unavailable, a 64-bit hash of the time and process ID is used.
+ The ``Xoroshiro128`` state vector consists of a 16-element array of 64-bit
+ unsigned integers.
- Notes
- -----
- See ``Xoroshiro128`` for a faster implementation that has a smaller
- period.
+ ``Xoroshiro1024`` is seeded using either a single 64-bit unsigned integer
+ or a vector of 64-bit unsigned integers. In either case, the seed is
+ used as an input for another simple random number generator,
+ SplitMix64, and the output of this PRNG function is used as the initial
+ state. Using a single 64-bit value for the seed can only initialize a
+ small range of the possible initial state values.
**Parallel Features**
- ``Xorshift1024`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{512}` random numbers have been generated. This
- allows the original sequence to be split so that distinct segments can be used
- in each worker process. All generators should be initialized with the same
- seed to ensure that the segments come from the same sequence.
+ ``Xoroshiro1024`` can be used in parallel applications by calling the
+ method ``jumped`` which advances the state as-if :math:`2^{512}` random
+ numbers have been generated. This allows the original sequence to be split
+ so that distinct segments can be used in each worker process. All
+ generators should be chained to ensure that the segments come from the same
+ sequence.
+
+ >>> from numpy.random import Generator, Xorshift1024
+ >>> bit_generator = Xorshift1024(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
- >>> from numpy.random import RandomGenerator, Xorshift1024
- >>> rg = [RandomGenerator(Xorshift1024(1234)) for _ in range(10)]
- # Advance each Xorshift1024 instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
-
- **State and Seeding**
-
- The ``Xorshift1024`` state vector consists of a 16 element array
- of 64-bit unsigned integers.
+ **Compatibility Guarantee**
- ``Xorshift1024`` is seeded using either a single 64-bit unsigned integer
- or a vector of 64-bit unsigned integers. In either case, the input seed is
- used as an input (or inputs) for another simple random number generator,
- Splitmix64, and the output of this PRNG function is used as the initial state.
- Using a single 64-bit value for the seed can only initialize a small range of
- the possible initial state values. When using an array, the SplitMix64 state
- for producing the ith component of the initial state is XORd with the ith
- value of the seed array until the seed array is exhausted. When using an array
- the initial state for the SplitMix64 state is 0 so that using a single element
- array and using the same value as a scalar will produce the same initial state.
+ ``Xorshift1024`` makes a guarantee that a fixed seed will always
+ produce the same random integer stream.
Examples
--------
- >>> from numpy.random import RandomGenerator, Xorshift1024
- >>> rg = RandomGenerator(Xorshift1024(1234))
- >>> rg.standard_normal()
- 0.123 # random
-
- Identical method using only Xoroshiro128
-
- >>> rg = Xorshift1024(1234).generator
+ >>> from numpy.random import Generator, Xorshift1024
+ >>> rg = Generator(Xorshift1024(1234))
>>> rg.standard_normal()
0.123 # random
@@ -130,32 +121,28 @@ cdef class Xorshift1024:
generators." CoRR, abs/1403.0930, 2014.
"""
- cdef xorshift1024_state *rng_state
- cdef brng_t *_brng
+ cdef xorshift1024_state rng_state
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None):
- self.rng_state = <xorshift1024_state *>malloc(sizeof(xorshift1024_state))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
self.seed(seed)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &xorshift1024_uint64
- self._brng.next_uint32 = &xorshift1024_uint32
- self._brng.next_double = &xorshift1024_double
- self._brng.next_raw = &xorshift1024_uint64
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &xorshift1024_uint64
+ self._bitgen.next_uint32 = &xorshift1024_uint32
+ self._bitgen.next_double = &xorshift1024_double
+ self._bitgen.next_raw = &xorshift1024_uint64
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
+ cdef const char *name = "BitGenerator"
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -165,16 +152,8 @@ cdef class Xorshift1024:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.has_uint32 = 0
@@ -184,7 +163,7 @@ cdef class Xorshift1024:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -209,10 +188,10 @@ cdef class Xorshift1024:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None):
"""
@@ -249,32 +228,48 @@ cdef class Xorshift1024:
self.rng_state.p = 0
self._reset_state_variables()
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**512 random numbers have been generated
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
-
- Returns
- -------
- self : Xorshift1024
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is required
- to ensure exact reproducibility.
"""
cdef np.npy_intp i
for i in range(iter):
- xorshift1024_jump(self.rng_state)
+ xorshift1024_jump(&self.rng_state)
self._reset_state_variables()
- return self
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(512 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
+
+ Returns
+ -------
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
+ """
+ cdef Xorshift1024 bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
@property
def state(self):
@@ -290,7 +285,7 @@ cdef class Xorshift1024:
s = np.empty(16, dtype=np.uint64)
for i in range(16):
s[i] = self.rng_state.s[i]
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
'state': {'s': s, 'p': self.rng_state.p},
'has_uint32': self.rng_state.has_uint32,
'uinteger': self.rng_state.uinteger}
@@ -299,8 +294,8 @@ cdef class Xorshift1024:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
for i in range(16):
@@ -324,10 +319,10 @@ cdef class Xorshift1024:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -346,24 +341,9 @@ cdef class Xorshift1024:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the core PRNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/xoshiro256starstar.pyx b/numpy/random/xoshiro256.pyx
index 278356b05..7258ea3fb 100644
--- a/numpy/random/xoshiro256starstar.pyx
+++ b/numpy/random/xoshiro256.pyx
@@ -1,45 +1,45 @@
-from libc.stdlib cimport malloc, free
-from cpython.pycapsule cimport PyCapsule_New
-
-import numpy as np
-cimport numpy as np
-
try:
from threading import Lock
except ImportError:
from dummy_threading import Lock
+from libc.string cimport memcpy
+from cpython.pycapsule cimport PyCapsule_New
+
+import numpy as np
+cimport numpy as np
+
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
np.import_array()
-cdef extern from "src/xoshiro256starstar/xoshiro256starstar.h":
+cdef extern from "src/xoshiro256/xoshiro256.h":
- struct s_xoshiro256starstar_state:
+ struct s_xoshiro256_state:
uint64_t s[4]
int has_uint32
uint32_t uinteger
- ctypedef s_xoshiro256starstar_state xoshiro256starstar_state
+ ctypedef s_xoshiro256_state xoshiro256_state
- uint64_t xoshiro256starstar_next64(xoshiro256starstar_state *state) nogil
- uint32_t xoshiro256starstar_next32(xoshiro256starstar_state *state) nogil
- void xoshiro256starstar_jump(xoshiro256starstar_state *state)
+ uint64_t xoshiro256_next64(xoshiro256_state *state) nogil
+ uint32_t xoshiro256_next32(xoshiro256_state *state) nogil
+ void xoshiro256_jump(xoshiro256_state *state)
-cdef uint64_t xoshiro256starstar_uint64(void* st) nogil:
- return xoshiro256starstar_next64(<xoshiro256starstar_state *>st)
+cdef uint64_t xoshiro256_uint64(void* st) nogil:
+ return xoshiro256_next64(<xoshiro256_state *>st)
-cdef uint32_t xoshiro256starstar_uint32(void *st) nogil:
- return xoshiro256starstar_next32(<xoshiro256starstar_state *> st)
+cdef uint32_t xoshiro256_uint32(void *st) nogil:
+ return xoshiro256_next32(<xoshiro256_state *> st)
-cdef double xoshiro256starstar_double(void* st) nogil:
- return uint64_to_double(xoshiro256starstar_next64(<xoshiro256starstar_state *>st))
+cdef double xoshiro256_double(void* st) nogil:
+ return uint64_to_double(xoshiro256_next64(<xoshiro256_state *>st))
-cdef class Xoshiro256StarStar:
+cdef class Xoshiro256:
"""
- Xoshiro256StarStar(seed=None)
+ Xoshiro256(seed=None)
Container for the xoshiro256** pseudo-random number generator.
@@ -47,75 +47,65 @@ cdef class Xoshiro256StarStar:
----------
seed : {None, int, array_like}, optional
Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**64-1], array of integers in
- [0, 2**64-1] or ``None`` (the default). If `seed` is ``None``,
- then ``Xoshiro256StarStar`` will try to read data from
- ``/dev/urandom`` (or the Windows analog) if available. If
- unavailable, a 64-bit hash of the time and process ID is used.
+ Can be an integer in [0, 2**64-1], array of integers in [0, 2**64-1]
+ or ``None`` (the default). If `seed` is ``None``, then data is read
+ from ``/dev/urandom`` (or the Windows analog) if available. If
+ unavailable, a hash of the time and process ID is used.
Notes
-----
xoshiro256** is written by David Blackman and Sebastiano Vigna.
- It is a 64-bit PRNG that uses a carefully linear transformation.
+ It is a 64-bit PRNG that uses a carefully constructed linear transformation.
This produces a fast PRNG with excellent statistical quality
[1]_. xoshiro256** has a period of :math:`2^{256} - 1`
and supports jumping the sequence in increments of :math:`2^{128}`,
- which allows multiple non-overlapping sequences to be generated.
+ which allows multiple non-overlapping subsequences to be generated.
- ``Xoshiro256StarStar`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
+ ``Xoshiro256`` provides a capsule containing function pointers that
+ produce doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
- **Compatibility Guarantee**
+ See ``Xorshift1024`` for a related PRNG with a different period
+ (:math:`2^{1024} - 1`) and jumped size (:math:`2^{512} - 1`).
- ``Xoshiro256StarStar`` guarantees that a fixed seed will always produce the
- same results.
+ **State and Seeding**
- See ``Xorshift1024`` for a related PRNG with different periods
- (:math:`2^{1024} - 1`) and jump size (:math:`2^{512} - 1`).
+ The ``Xoshiro256`` state vector consists of a 4-element array
+ of 64-bit unsigned integers.
- **Parallel Features**
+ ``Xoshiro256`` is seeded using either a single 64-bit unsigned
+ integer or a vector of 64-bit unsigned integers. In either case, the seed
+ is used as an input for another simple random number generator, SplitMix64,
+ and the output of this PRNG function is used as the initial state. Using
+ a single 64-bit value for the seed can only initialize a small range of
+ the possible initial state values.
- ``Xoshiro256StarStar`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{128}` random numbers have been generated. This
- allow the original sequence to be split so that distinct segments can be used
- in each worker process. All generators should be initialized with the same
- seed to ensure that the segments come from the same sequence.
+ **Parallel Features**
- >>> from numpy.random import RandomGenerator, Xoshiro256StarStar
- >>> rg = [RandomGenerator(Xoshiro256StarStar(1234)) for _ in range(10)]
- # Advance each Xoshiro256StarStar instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
+ ``Xoshiro256`` can be used in parallel applications by calling the
+ method ``jumped`` which advances the state as-if :math:`2^{128}` random
+ numbers have been generated. This allows the original sequence to be split
+ so that distinct segments can be used in each worker process. All
+ generators should be chained to ensure that the segments come from the same
+ sequence.
- **State and Seeding**
+ >>> from numpy.random import Generator, Xoshiro256
+ >>> bit_generator = Xoshiro256(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... bit_generator = bit_generator.jumped()
- The ``Xoshiro256StarStar`` state vector consists of a 4 element array
- of 64-bit unsigned integers.
+ **Compatibility Guarantee**
- ``Xoshiro256StarStar`` is seeded using either a single 64-bit unsigned
- integer or a vector of 64-bit unsigned integers. In either case, the
- input seed is used as an input (or inputs) for another simple random
- number generator, Splitmix64, and the output of this PRNG function is
- used as the initial state. Using a single 64-bit value for the seed can
- only initialize a small range of the possible initial state values. When
- using an array, the SplitMix64 state for producing the ith component of
- the initial state is XORd with the ith value of the seed array until the
- seed array is exhausted. When using an array the initial state for the
- SplitMix64 state is 0 so that using a single element array and using the
- same value as a scalar will produce the same initial state.
+ ``Xoshiro256`` makes a guarantee that a fixed seed will always
+ produce the same random integer stream.
Examples
--------
- >>> from numpy.random import RandomGenerator, Xoshiro256StarStar
- >>> rg = RandomGenerator(Xoshiro256StarStar(1234))
- >>> rg.standard_normal()
- 0.123 # random
-
- Identical method using only Xoshiro256StarStar
-
- >>> rg = Xoshiro256StarStar(1234).generator
+ >>> from numpy.random import Generator, Xoshiro256
+ >>> rg = Generator(Xoshiro256(1234))
>>> rg.standard_normal()
0.123 # random
@@ -124,32 +114,28 @@ cdef class Xoshiro256StarStar:
.. [1] "xoroshiro+ / xorshift* / xorshift+ generators and the PRNG shootout",
http://xorshift.di.unimi.it/
"""
- cdef xoshiro256starstar_state *rng_state
- cdef brng_t *_brng
+ cdef xoshiro256_state rng_state
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None):
- self.rng_state = <xoshiro256starstar_state *>malloc(sizeof(xoshiro256starstar_state))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
self.seed(seed)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &xoshiro256starstar_uint64
- self._brng.next_uint32 = &xoshiro256starstar_uint32
- self._brng.next_double = &xoshiro256starstar_double
- self._brng.next_raw = &xoshiro256starstar_uint64
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &xoshiro256_uint64
+ self._bitgen.next_uint32 = &xoshiro256_uint32
+ self._bitgen.next_double = &xoshiro256_double
+ self._bitgen.next_raw = &xoshiro256_uint64
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
+ cdef const char *name = "BitGenerator"
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -159,16 +145,8 @@ cdef class Xoshiro256StarStar:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.has_uint32 = 0
@@ -178,7 +156,7 @@ cdef class Xoshiro256StarStar:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -203,10 +181,10 @@ cdef class Xoshiro256StarStar:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None):
"""
@@ -243,32 +221,48 @@ cdef class Xoshiro256StarStar:
self.rng_state.s[3] = <uint64_t>int(state[3])
self._reset_state_variables()
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**128 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
-
- Returns
- -------
- self : Xoshiro256StarStar
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is required
- to ensure exact reproducibility.
"""
cdef np.npy_intp i
for i in range(iter):
- xoshiro256starstar_jump(self.rng_state)
+ xoshiro256_jump(&self.rng_state)
self._reset_state_variables()
- return self
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(128 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
+
+ Returns
+ -------
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
+ """
+ cdef Xoshiro256 bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
@property
def state(self):
@@ -286,7 +280,7 @@ cdef class Xoshiro256StarStar:
state[1] = self.rng_state.s[1]
state[2] = self.rng_state.s[2]
state[3] = self.rng_state.s[3]
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
's': state,
'has_uint32': self.rng_state.has_uint32,
'uinteger': self.rng_state.uinteger}
@@ -295,8 +289,8 @@ cdef class Xoshiro256StarStar:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
self.rng_state.s[0] = <uint64_t>value['s'][0]
@@ -321,10 +315,10 @@ cdef class Xoshiro256StarStar:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -343,24 +337,9 @@ cdef class Xoshiro256StarStar:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the basic RNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator
diff --git a/numpy/random/xoshiro512starstar.pyx b/numpy/random/xoshiro512.pyx
index 65d4c7c3e..a2c0a4896 100644
--- a/numpy/random/xoshiro512starstar.pyx
+++ b/numpy/random/xoshiro512.pyx
@@ -3,43 +3,43 @@ try:
except ImportError:
from dummy_threading import Lock
-from libc.stdlib cimport malloc, free
+from libc.string cimport memcpy
from cpython.pycapsule cimport PyCapsule_New
import numpy as np
cimport numpy as np
from .common cimport *
-from .distributions cimport brng_t
+from .distributions cimport bitgen_t
from .entropy import random_entropy, seed_by_array
np.import_array()
-cdef extern from "src/xoshiro512starstar/xoshiro512starstar.h":
+cdef extern from "src/xoshiro512/xoshiro512.h":
- struct s_xoshiro512starstar_state:
+ struct s_xoshiro512_state:
uint64_t s[8]
int has_uint32
uint32_t uinteger
- ctypedef s_xoshiro512starstar_state xoshiro512starstar_state
+ ctypedef s_xoshiro512_state xoshiro512_state
- uint64_t xoshiro512starstar_next64(xoshiro512starstar_state *state) nogil
- uint32_t xoshiro512starstar_next32(xoshiro512starstar_state *state) nogil
- void xoshiro512starstar_jump(xoshiro512starstar_state *state)
+ uint64_t xoshiro512_next64(xoshiro512_state *state) nogil
+ uint32_t xoshiro512_next32(xoshiro512_state *state) nogil
+ void xoshiro512_jump(xoshiro512_state *state)
-cdef uint64_t xoshiro512starstar_uint64(void* st) nogil:
- return xoshiro512starstar_next64(<xoshiro512starstar_state *>st)
+cdef uint64_t xoshiro512_uint64(void* st) nogil:
+ return xoshiro512_next64(<xoshiro512_state *>st)
-cdef uint32_t xoshiro512starstar_uint32(void *st) nogil:
- return xoshiro512starstar_next32(<xoshiro512starstar_state *> st)
+cdef uint32_t xoshiro512_uint32(void *st) nogil:
+ return xoshiro512_next32(<xoshiro512_state *> st)
-cdef double xoshiro512starstar_double(void* st) nogil:
- return uint64_to_double(xoshiro512starstar_next64(<xoshiro512starstar_state *>st))
+cdef double xoshiro512_double(void* st) nogil:
+ return uint64_to_double(xoshiro512_next64(<xoshiro512_state *>st))
-cdef class Xoshiro512StarStar:
+cdef class Xoshiro512:
"""
- Xoshiro512StarStar(seed=None)
+ Xoshiro512(seed=None)
Container for the xoshiro512** pseudo-random number generator.
@@ -47,75 +47,66 @@ cdef class Xoshiro512StarStar:
----------
seed : {None, int, array_like}, optional
Random seed initializing the pseudo-random number generator.
- Can be an integer in [0, 2**64-1], array of integers in
- [0, 2**64-1] or ``None`` (the default). If `seed` is ``None``,
- then ``Xoshiro512StarStar`` will try to read data from
- ``/dev/urandom`` (or the Windows analog) if available. If
- unavailable, a 64-bit hash of the time and process ID is used.
+ Can be an integer in [0, 2**64-1], array of integers in [0, 2**64-1]
+ or ``None`` (the default). If `seed` is ``None``, then data is read
+ from ``/dev/urandom`` (or the Windows analog) if available. If
+ unavailable, a hash of the time and process ID is used.
Notes
-----
xoshiro512** is written by David Blackman and Sebastiano Vigna.
- It is a 64-bit PRNG that uses a carefully linear transformation.
+ It is a 64-bit PRNG that uses a carefully constructed linear transformation.
This produces a fast PRNG with excellent statistical quality
[1]_. xoshiro512** has a period of :math:`2^{512} - 1`
and supports jumping the sequence in increments of :math:`2^{256}`,
- which allows multiple non-overlapping sequences to be generated.
+ which allows multiple non-overlapping subsequences to be generated.
- ``Xoshiro512StarStar`` exposes no user-facing API except ``generator``,
- ``state``, ``cffi`` and ``ctypes``. Designed for use in a
- ``RandomGenerator`` object.
+ ``Xoshiro512`` provides a capsule containing function pointers that
+ produce doubles, and unsigned 32 and 64- bit integers. These are not
+ directly consumable in Python and must be consumed by a ``Generator``
+ or similar object that supports low-level access.
- **Compatibility Guarantee**
+ See ``Xorshift1024`` for a related PRNG with a different period
+ (:math:`2^{1024} - 1`) and jumped size (:math:`2^{512} - 1`).
+
+ **State and Seeding**
- ``Xoshiro512StarStar`` guarantees that a fixed seed will always produce the
- same results.
+ The ``Xoshiro512`` state vector consists of a 4 element array
+ of 64-bit unsigned integers.
- See ``Xorshift1024`` for a related PRNG with different periods
- (:math:`2^{1024} - 1`) and jump size (:math:`2^{512} - 1`).
+ ``Xoshiro512`` is seeded using either a single 64-bit unsigned
+ integer or a vector of 64-bit unsigned integers. In either case, the seed
+ is used as an input for another simple random number generator, SplitMix64,
+ and the output of this PRNG function is used as the initial state. Using
+ a single 64-bit value for the seed can only initialize a small range of
+ the possible initial state values.
**Parallel Features**
- ``Xoshiro512StarStar`` can be used in parallel applications by
- calling the method ``jump`` which advances the state as-if
- :math:`2^{128}` random numbers have been generated. This
- allow the original sequence to be split so that distinct segments can be used
- in each worker process. All generators should be initialized with the same
- seed to ensure that the segments come from the same sequence.
-
- >>> from numpy.random import RandomGenerator, Xoshiro512StarStar
- >>> rg = [RandomGenerator(Xoshiro512StarStar(1234)) for _ in range(10)]
- # Advance each Xoshiro512StarStar instance by i jumps
- >>> for i in range(10):
- ... rg[i].brng.jump(i)
+ ``Xoshiro512`` can be used in parallel applications by calling the
+ method ``jumped`` which advances the state as-if :math:`2^{128}` random
+ numbers have been generated. This allows the original sequence to be split
+ so that distinct segments can be used in each worker process. All
+ generators should be chained to ensure that the segments come from the same
+ sequence.
+
+ >>> from numpy.random import Generator, Xoshiro512
+ >>> bit_generator = Xoshiro512(1234)
+ >>> rg = []
+ >>> for _ in range(10):
+ ... rg.append(Generator(bit_generator))
+ ... # Chain the BitGenerators
+ ... bit_generator = bit_generator.jumped()
- **State and Seeding**
-
- The ``Xoshiro512StarStar`` state vector consists of a 4 element array
- of 64-bit unsigned integers.
+ **Compatibility Guarantee**
- ``Xoshiro512StarStar`` is seeded using either a single 64-bit unsigned
- integer or a vector of 64-bit unsigned integers. In either case, the
- input seed is used as an input (or inputs) for another simple random
- number generator, Splitmix64, and the output of this PRNG function is
- used as the initial state. Using a single 64-bit value for the seed can
- only initialize a small range of the possible initial state values. When
- using an array, the SplitMix64 state for producing the ith component of
- the initial state is XORd with the ith value of the seed array until the
- seed array is exhausted. When using an array the initial state for the
- SplitMix64 state is 0 so that using a single element array and using the
- same value as a scalar will produce the same initial state.
+ ``Xoshiro512`` makes a guarantee that a fixed seed will always
+ produce the same random integer stream.
Examples
--------
- >>> from numpy.random import RandomGenerator, Xoshiro512StarStar
- >>> rg = RandomGenerator(Xoshiro512StarStar(1234))
- >>> rg.standard_normal()
- 0.123 # random
-
- Identical method using only Xoshiro512StarStar
-
- >>> rg = Xoshiro512StarStar(1234).generator
+ >>> from numpy.random import Generator, Xoshiro512
+ >>> rg = Generator(Xoshiro512(1234))
>>> rg.standard_normal()
0.123 # random
@@ -124,32 +115,28 @@ cdef class Xoshiro512StarStar:
.. [1] "xoroshiro+ / xorshift* / xorshift+ generators and the PRNG shootout",
http://xorshift.di.unimi.it/
"""
- cdef xoshiro512starstar_state *rng_state
- cdef brng_t *_brng
+ cdef xoshiro512_state rng_state
+ cdef bitgen_t _bitgen
cdef public object capsule
cdef object _ctypes
cdef object _cffi
- cdef object _generator
cdef public object lock
def __init__(self, seed=None):
- self.rng_state = <xoshiro512starstar_state *>malloc(sizeof(xoshiro512starstar_state))
- self._brng = <brng_t *>malloc(sizeof(brng_t))
self.seed(seed)
self.lock = Lock()
- self._brng.state = <void *>self.rng_state
- self._brng.next_uint64 = &xoshiro512starstar_uint64
- self._brng.next_uint32 = &xoshiro512starstar_uint32
- self._brng.next_double = &xoshiro512starstar_double
- self._brng.next_raw = &xoshiro512starstar_uint64
+ self._bitgen.state = <void *>&self.rng_state
+ self._bitgen.next_uint64 = &xoshiro512_uint64
+ self._bitgen.next_uint32 = &xoshiro512_uint32
+ self._bitgen.next_double = &xoshiro512_double
+ self._bitgen.next_raw = &xoshiro512_uint64
self._ctypes = None
self._cffi = None
- self._generator = None
- cdef const char *name = "BasicRNG"
- self.capsule = PyCapsule_New(<void *>self._brng, name, NULL)
+ cdef const char *name = "BitGenerator"
+ self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
# Pickling support:
def __getstate__(self):
@@ -159,16 +146,8 @@ cdef class Xoshiro512StarStar:
self.state = state
def __reduce__(self):
- from ._pickle import __brng_ctor
- return (__brng_ctor,
- (self.state['brng'],),
- self.state)
-
- def __dealloc__(self):
- if self.rng_state:
- free(self.rng_state)
- if self._brng:
- free(self._brng)
+ from ._pickle import __bit_generator_ctor
+ return __bit_generator_ctor, (self.state['bit_generator'],), self.state
cdef _reset_state_variables(self):
self.rng_state.has_uint32 = 0
@@ -178,7 +157,7 @@ cdef class Xoshiro512StarStar:
"""
random_raw(self, size=None)
- Return randoms as generated by the underlying BasicRNG
+ Return randoms as generated by the underlying BitGenerator
Parameters
----------
@@ -203,10 +182,10 @@ cdef class Xoshiro512StarStar:
See the class docstring for the number of bits returned.
"""
- return random_raw(self._brng, self.lock, size, output)
+ return random_raw(&self._bitgen, self.lock, size, output)
def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(self._brng, self.lock, cnt, method)
+ return benchmark(&self._bitgen, self.lock, cnt, method)
def seed(self, seed=None):
"""
@@ -241,32 +220,48 @@ cdef class Xoshiro512StarStar:
self.rng_state.s[i] = <uint64_t>int(state[i])
self._reset_state_variables()
- def jump(self, np.npy_intp iter=1):
+ cdef jump_inplace(self, np.npy_intp iter):
"""
- jump(iter=1)
+ Jump state in-place
- Jumps the state as-if 2**256 random numbers have been generated.
+ Not part of public API
Parameters
----------
iter : integer, positive
Number of times to jump the state of the rng.
-
- Returns
- -------
- self : Xoshiro512StarStar
- PRNG jumped iter times
-
- Notes
- -----
- Jumping the rng state resets any pre-computed random numbers. This is required
- to ensure exact reproducibility.
"""
cdef np.npy_intp i
for i in range(iter):
- xoshiro512starstar_jump(self.rng_state)
+ xoshiro512_jump(&self.rng_state)
self._reset_state_variables()
- return self
+
+ def jumped(self, np.npy_intp iter=1):
+ """
+ jumped(iter=1)
+
+ Returns a new bit generator with the state jumped
+
+ The state of the returned big generator is jumped as-if
+ 2**(256 * iter) random numbers have been generated.
+
+ Parameters
+ ----------
+ iter : integer, positive
+ Number of times to jump the state of the bit generator returned
+
+ Returns
+ -------
+ bit_generator : Xoroshiro128
+ New instance of generator jumped iter times
+ """
+ cdef Xoshiro512 bit_generator
+
+ bit_generator = self.__class__()
+ bit_generator.state = self.state
+ bit_generator.jump_inplace(iter)
+
+ return bit_generator
@property
def state(self):
@@ -282,7 +277,7 @@ cdef class Xoshiro512StarStar:
state = np.empty(8, dtype=np.uint64)
for i in range(8):
state[i] = self.rng_state.s[i]
- return {'brng': self.__class__.__name__,
+ return {'bit_generator': self.__class__.__name__,
's': state,
'has_uint32': self.rng_state.has_uint32,
'uinteger': self.rng_state.uinteger}
@@ -291,8 +286,8 @@ cdef class Xoshiro512StarStar:
def state(self, value):
if not isinstance(value, dict):
raise TypeError('state must be a dict')
- brng = value.get('brng', '')
- if brng != self.__class__.__name__:
+ bitgen = value.get('bit_generator', '')
+ if bitgen != self.__class__.__name__:
raise ValueError('state must be for a {0} '
'PRNG'.format(self.__class__.__name__))
for i in range(8):
@@ -315,10 +310,10 @@ cdef class Xoshiro512StarStar:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._ctypes is None:
- self._ctypes = prepare_ctypes(self._brng)
+ self._ctypes = prepare_ctypes(&self._bitgen)
return self._ctypes
@@ -337,24 +332,9 @@ cdef class Xoshiro512StarStar:
* next_uint64 - function pointer to produce 64 bit integers
* next_uint32 - function pointer to produce 32 bit integers
* next_double - function pointer to produce doubles
- * brng - pointer to the Basic RNG struct
+ * bitgen - pointer to the bit generator struct
"""
if self._cffi is not None:
return self._cffi
- self._cffi = prepare_cffi(self._brng)
+ self._cffi = prepare_cffi(&self._bitgen)
return self._cffi
-
- @property
- def generator(self):
- """
- Return a RandomGenerator object
-
- Returns
- -------
- gen : numpy.random.RandomGenerator
- Random generator used this instance as the basic RNG
- """
- if self._generator is None:
- from .generator import RandomGenerator
- self._generator = RandomGenerator(self)
- return self._generator