Debian Codegraph @

vendor/pcg/pcg-advance-128.c

raw symbols SCIP
1 /*
2 * PCG Random Number Generation for C.
3 *
4 * Copyright 2014-2019 Melissa O'Neill <[email protected]>,
5 * and the PCG Project contributors.
6 *
7 * SPDX-License-Identifier: (Apache-2.0 OR MIT)
8 *
9 * Licensed under the Apache License, Version 2.0 (provided in
10 * LICENSE-APACHE.txt and at http://www.apache.org/licenses/LICENSE-2.0)
11 * or under the MIT license (provided in LICENSE-MIT.txt and at
12 * http://opensource.org/licenses/MIT), at your option. This file may not
13 * be copied, modified, or distributed except according to those terms.
14 *
15 * Distributed on an "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, either
16 * express or implied. See your chosen license for details.
17 *
18 * For additional information about the PCG random number generation scheme,
19 * visit http://www.pcg-random.org/.
20 */
21
22 /*
23 * This code is derived from the canonical C++ PCG implementation, which
24 * has many additional features and is preferable if you can use C++ in
25 * your project.
26 *
27 * Repetative C code is derived using C preprocessor metaprogramming
28 * techniques.
29 */
30
31 #include "pcg_variants.h"cxx . . $ `<file>/vendor/pcg/pcg_variants.h`/
32
33 /* Multi-step advance functions (jump-ahead, jump-back)
34 *
35 * The method used here is based on Brown, "Random Number Generation
36 * with Arbitrary Stride,", Transactions of the American Nuclear
37 * Society (Nov. 1994). The algorithm is very similar to fast
38 * exponentiation.
39 *
40 * Even though delta is an unsigned integer, we can pass a
41 * signed integer to go backwards, it just goes "the long way round".
42 */
43
44 #if PCG_HAS_128BIT_OPScxx . . $ `vendor/pcg/pcg_variants.h:50:13`!
45 pcg128_tcxx . . $ pcg128_t# pcg_advance_lcg_128cxx . . $ pcg_advance_lcg_128(1fcf4e06d8f35bdc).(pcg128_tcxx . . $ pcg128_t# state, pcg128_tcxx . . $ pcg128_t# delta, pcg128_tcxx . . $ pcg128_t# cur_mult,
46 pcg128_tcxx . . $ pcg128_t# cur_plus)
47 {
48 pcg128_tcxx . . $ pcg128_t# acc_mult = 1u;
49 pcg128_tcxx . . $ pcg128_t# acc_plus = 0u;
50 while (delta > 0) {
51 if (delta & 1) {
52 acc_mult *= cur_mult;
53 acc_plus = acc_plus * cur_mult + cur_plus;
54 }
55 cur_plus = (cur_mult + 1) * cur_plus;
56 cur_mult *= cur_mult;
57 delta /= 2;
58 }
59 return acc_mult * state + acc_plus;
60 }
61 #endif