summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-06-25 11:17:24 -0700
committerGitHub <noreply@github.com>2019-06-25 11:17:24 -0700
commita1cd310ea6192945b7f4e452ad5794b291da77a5 (patch)
treea65532df7fdeef1fce62528a29f87324d4c2afc6 /numpy
parent5a7a4a450295ebe0eb37905d967a3279d4ccdc4d (diff)
parent083be1f81f25fc548f091f72105f69391bc1a33d (diff)
downloadnumpy-a1cd310ea6192945b7f4e452ad5794b291da77a5.tar.gz
Merge pull request #13832 from mattip/remove-pcg32
MAINT: remove pcg32 BitGenerator
Diffstat (limited to 'numpy')
-rw-r--r--numpy/random/__init__.py4
-rw-r--r--numpy/random/_pickle.py2
-rw-r--r--numpy/random/pcg32.pyx402
-rw-r--r--numpy/random/pcg64.pyx2
-rw-r--r--numpy/random/setup.py2
-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.h86
-rw-r--r--numpy/random/src/pcg32/pcg_variants.h2210
-rw-r--r--numpy/random/tests/test_direct.py16
-rw-r--r--numpy/random/tests/test_smoke.py15
13 files changed, 4 insertions, 2908 deletions
diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py
index 968f3361c..cf4a874af 100644
--- a/numpy/random/__init__.py
+++ b/numpy/random/__init__.py
@@ -98,7 +98,6 @@ set_state Set state of generator.
BitGenerator Streams that work with Generator
--------------------------------------------- ---
MT19937
-PCG32
PCG64
Philox
ThreeFry
@@ -166,7 +165,6 @@ from . import mtrand
from .mtrand import *
from .generator import Generator
from .mt19937 import MT19937
-from .pcg32 import PCG32
from .pcg64 import PCG64
from .philox import Philox
from .threefry import ThreeFry
@@ -174,7 +172,7 @@ from .xoshiro256 import Xoshiro256
from .xoshiro512 import Xoshiro512
from .mtrand import RandomState
-__all__ += ['Generator', 'MT19937', 'Philox', 'PCG64', 'PCG32',
+__all__ += ['Generator', 'MT19937', 'Philox', 'PCG64',
'ThreeFry', 'Xoshiro256', 'Xoshiro512', 'RandomState']
diff --git a/numpy/random/_pickle.py b/numpy/random/_pickle.py
index a1f8ab34e..bb637a69c 100644
--- a/numpy/random/_pickle.py
+++ b/numpy/random/_pickle.py
@@ -1,7 +1,6 @@
from .mtrand import RandomState
from .philox import Philox
from .threefry import ThreeFry
-from .pcg32 import PCG32
from .pcg64 import PCG64
from .xoshiro256 import Xoshiro256
from .xoshiro512 import Xoshiro512
@@ -10,7 +9,6 @@ from .generator import Generator
from .mt19937 import MT19937
BitGenerators = {'MT19937': MT19937,
- 'PCG32': PCG32,
'PCG64': PCG64,
'Philox': Philox,
'ThreeFry': ThreeFry,
diff --git a/numpy/random/pcg32.pyx b/numpy/random/pcg32.pyx
deleted file mode 100644
index 612a1b58d..000000000
--- a/numpy/random/pcg32.pyx
+++ /dev/null
@@ -1,402 +0,0 @@
-try:
- from threading import Lock
-except ImportError:
- from dummy_threading import Lock
-
-from cpython.pycapsule cimport PyCapsule_New
-
-import numpy as np
-cimport numpy as np
-
-from .common cimport *
-from .distributions cimport bitgen_t
-from .entropy import random_entropy
-
-__all__ = ['PCG32']
-
-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.
-
- 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.
-
- Attributes
- ----------
- lock: threading.Lock
- Lock instance that is shared so that the same bit git generator can
- be used in multiple Generators without corrupting the state. Code that
- generates values from a bit generator should hold the bit generator's
- lock.
-
- Notes
- -----
- 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`` 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.
-
- Supports the method advance to advance the RNG an arbitrary number of
- steps. The state of the PCG-32 PRNG is represented by 2 64-bit unsigned
- integers.
-
- See ``PCG64`` for a similar implementation with a smaller period.
-
- **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.
-
- **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 Generator, PCG32
- >>> rg = [Generator(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 = [Generator(PCG32(1234, i + 1)) for i in range(10)]
- >>> for i in range(10):
- ... rg[i].bit_generator.advance(i * 2**32)
-
- **Compatibility Guarantee**
-
- ``PCG32`` makes a guarantee that a fixed seed and will always produce
- the same random integer 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 pcg32_random_t pcg32_random_state
- cdef bitgen_t _bitgen
- cdef public object capsule
- cdef object _ctypes
- cdef object _cffi
- cdef public object lock
-
- def __init__(self, seed=None, inc=0):
- self.rng_state.pcg_state = &self.pcg32_random_state
- self.seed(seed, inc)
- self.lock = Lock()
-
- self._bitgen.state = <void *>&self.rng_state
- self._bitgen.next_uint64 = &pcg32_uint64
- self._bitgen.next_uint32 = &pcg32_uint32
- self._bitgen.next_double = &pcg32_double
- self._bitgen.next_raw = &pcg32_raw
-
- self._ctypes = None
- self._cffi = None
-
- cdef const char *name = "BitGenerator"
- self.capsule = PyCapsule_New(<void *>&self._bitgen, name, NULL)
-
- # Pickling support:
- def __getstate__(self):
- return self.state
-
- def __setstate__(self, state):
- self.state = state
-
- def __reduce__(self):
- 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 BitGenerator
-
- 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._bitgen, self.lock, size, output)
-
- def _benchmark(self, Py_ssize_t cnt, method=u'uint64'):
- return benchmark(&self._bitgen, self.lock, cnt, method)
-
- def seed(self, seed=None, inc=0):
- """
- seed(seed=None, inc=0)
-
- Seed the generator.
-
- This method is called at initialization. It can be called again to
- re-seed the generator.
-
- Parameters
- ----------
- seed : int, optional
- Seed for ``PCG64``. Integer between 0 and 2**64-1.
- inc : int, optional
- Increment to use for PCG stream. Integer between 0 and 2**64-1.
-
- 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)
-
- 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.
-
- Notes
- -----
- The step size is phi when divided by the period 2**64
- """
- step = int(0x9e3779b97f4a7c16)
- self.advance(iter * step)
-
- def jumped(self, jumps=1):
- """
- jumped(jumps=1)
-
- Returns a new bit generator with the state jumped
-
- Jumps the state as-if 11400714819323198486 * jumps random numbers
- have been generated.
-
- Parameters
- ----------
- jumps : integer, positive
- Number of times to jump the state of the bit generator returned
-
- Returns
- -------
- bit_generator : PCG32
- New instance of generator jumped iter times
-
- Notes
- -----
- The jump size is phi-1 when divided by the period 2**64
- """
- cdef PCG32 bit_generator
-
- bit_generator = self.__class__()
- bit_generator.state = self.state
- bit_generator.jump_inplace(jumps)
-
- return bit_generator
-
- @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 {'bit_generator': 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')
- 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.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.
- """
- delta = wrap_int(delta, 64)
- pcg32_advance_state(&self.rng_state, <uint64_t>delta)
- return self
-
- @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
- * bitgen - pointer to the bit generator struct
- """
- if self._ctypes is None:
- self._ctypes = prepare_ctypes(&self._bitgen)
-
- 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
- * bitgen - pointer to the bit generator struct
- """
- if self._cffi is not None:
- return self._cffi
- self._cffi = prepare_cffi(&self._bitgen)
- return self._cffi
diff --git a/numpy/random/pcg64.pyx b/numpy/random/pcg64.pyx
index 7ff9ba6bf..b45f7d7c8 100644
--- a/numpy/random/pcg64.pyx
+++ b/numpy/random/pcg64.pyx
@@ -88,8 +88,6 @@ cdef class PCG64:
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.
-
**State and Seeding**
The ``PCG64`` state vector consists of 2 unsigned 128-bit values,
diff --git a/numpy/random/setup.py b/numpy/random/setup.py
index 84e9f1c68..f00373233 100644
--- a/numpy/random/setup.py
+++ b/numpy/random/setup.py
@@ -86,7 +86,7 @@ def configuration(parent_package='', top_path=None):
define_macros=defs,
)
for gen in ['philox', 'threefry', 'xoshiro256', 'xoshiro512',
- 'pcg64', 'pcg32']:
+ 'pcg64']:
# gen.pyx, src/gen/gen.c
_defs = defs + PCG64_DEFS if gen == 'pcg64' else defs
config.add_extension(gen,
diff --git a/numpy/random/src/pcg32/LICENSE.md b/numpy/random/src/pcg32/LICENSE.md
deleted file mode 100644
index e28ef1a8b..000000000
--- a/numpy/random/src/pcg32/LICENSE.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# PCG32
-
-## The MIT License
-
-PCG Random Number Generation for C.
-
-Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 32c6b693d..000000000
--- a/numpy/random/src/pcg32/pcg32.h
+++ /dev/null
@@ -1,86 +0,0 @@
-#ifndef _RANDOMDGEN__PCG32_H_
-#define _RANDOMDGEN__PCG32_H_
-
-#include <inttypes.h>
-
-#ifdef _WIN32
-#define inline __forceinline
-#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/tests/test_direct.py b/numpy/random/tests/test_direct.py
index 534fe2b6d..051199217 100644
--- a/numpy/random/tests/test_direct.py
+++ b/numpy/random/tests/test_direct.py
@@ -6,7 +6,7 @@ from numpy.testing import (assert_equal, assert_allclose, assert_array_equal,
assert_raises)
import pytest
-from numpy.random import (Generator, MT19937, ThreeFry, PCG32, PCG64,
+from numpy.random import (Generator, MT19937, ThreeFry, PCG64,
Philox, Xoshiro256, Xoshiro512, RandomState)
from numpy.random.common import interface
@@ -435,20 +435,6 @@ class TestPCG64(Base):
assert val_neg == val_pos
assert val_big == val_pos
-class TestPCG32(TestPCG64):
- @classmethod
- def setup_class(cls):
- cls.bit_generator = 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)]
-
class TestMT19937(Base):
@classmethod
diff --git a/numpy/random/tests/test_smoke.py b/numpy/random/tests/test_smoke.py
index ba7f72159..d571e6548 100644
--- a/numpy/random/tests/test_smoke.py
+++ b/numpy/random/tests/test_smoke.py
@@ -6,7 +6,7 @@ import numpy as np
import pytest
from numpy.testing import assert_equal, assert_, assert_array_equal
from numpy.random import (Generator, MT19937, ThreeFry,
- PCG32, PCG64, Philox, Xoshiro256, Xoshiro512,
+ PCG64, Philox, Xoshiro256, Xoshiro512,
entropy)
@@ -867,16 +867,3 @@ class TestPCG64(RNG):
seed = np.array([1, 2, 3, out_of_bounds])
with pytest.raises(error_type):
self.rg.bit_generator.seed(seed)
-
-
-class TestPCG32(TestPCG64):
- @classmethod
- def setup_class(cls):
- cls.bit_generator = 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 = Generator(cls.bit_generator(*cls.seed))
- cls.initial_state = cls.rg.bit_generator.state
- cls.seed_vector_bits = None
- cls._extra_setup()