LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
rand_state.h 文件参考
#include "impl/longlong.h"
#include "lmmp/lmmp.h"
rand_state.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

结构体

struct  pcg64_128_state
 Copyright (C) 2026 HJimmyK (Jericho Knox) 更多...
struct  pcg64_le_seq_t
struct  xoshiro256pp_state

宏定义

#define LMMP_INLINE   static inline
#define PCG128_DEFAULT_MULTIPLIER_HI   0x2360ED051FC65DA4ULL
#define PCG128_DEFAULT_MULTIPLIER_LO   0x4385DF649FCCF645ULL
#define PCG64_LE_INCREMENT   1442695040888963407ULL
#define PCG64_LE_MULTIPLIER   6364136223846793005ULL

函数

static mp_limb_t lmmp_pcg64_128_random (pcg64_128_state *rng)
static void lmmp_pcg64_128_srandom (pcg64_128_state *rng, mp_limb_t seed)
mp_limb_t lmmp_randlimb_ (void)
 依据全局状态获取单个随机limb(0 - B 均匀分布)
static mp_limb_t lmmp_seed_generator (mp_limb_t seed)
 种子生成器
static mp_limb_t lmmp_xoshiro256pp_random (xoshiro256pp_state *rng)
static void lmmp_xoshiro256pp_srandom (xoshiro256pp_state *rng, mp_limb_t seed)
static mp_limb_t mix64 (mp_limb_t h)
static void pcg64_128_action (mp_limb_t state[2], const mp_limb_t inc[2])
static mp_limb_t pcg64_le_action (mp_limb_t *restrict state)
static void pcg64_le_seq_init (pcg64_le_seq_t *rng, mp_size_t i, mp_limb_t seed)
static void pcg64_le_seq_next (mp_ptr restrict dst, mp_size_t n, pcg64_le_seq_t *rng)
static mp_limb_t rotl (const mp_limb_t x, int k)

结构体说明

◆ pcg64_128_state

struct pcg64_128_state

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 rand_state.h 第 29 行定义.

pcg64_128_state 的协作图:
成员变量
mp_limb_t inc[2]
mp_limb_t state[2]

◆ pcg64_le_seq_t

struct pcg64_le_seq_t

在文件 rand_state.h 第 135 行定义.

pcg64_le_seq_t 的协作图:
成员变量
mp_size_t k
mp_limb_t *restrict state

◆ xoshiro256pp_state

struct xoshiro256pp_state

在文件 rand_state.h 第 34 行定义.

xoshiro256pp_state 的协作图:
成员变量
mp_limb_t s[4]

宏定义说明

◆ LMMP_INLINE

#define LMMP_INLINE   static inline

在文件 rand_state.h 第 41 行定义.

◆ PCG128_DEFAULT_MULTIPLIER_HI

#define PCG128_DEFAULT_MULTIPLIER_HI   0x2360ED051FC65DA4ULL

在文件 rand_state.h 第 38 行定义.

被这些函数引用 pcg64_128_action().

◆ PCG128_DEFAULT_MULTIPLIER_LO

#define PCG128_DEFAULT_MULTIPLIER_LO   0x4385DF649FCCF645ULL

在文件 rand_state.h 第 39 行定义.

被这些函数引用 pcg64_128_action().

◆ PCG64_LE_INCREMENT

#define PCG64_LE_INCREMENT   1442695040888963407ULL

在文件 rand_state.h 第 133 行定义.

被这些函数引用 pcg64_le_action() , 以及 pcg64_le_seq_next().

◆ PCG64_LE_MULTIPLIER

#define PCG64_LE_MULTIPLIER   6364136223846793005ULL

在文件 rand_state.h 第 132 行定义.

被这些函数引用 pcg64_le_action() , 以及 pcg64_le_seq_next().

函数说明

◆ lmmp_pcg64_128_random()

mp_limb_t lmmp_pcg64_128_random ( pcg64_128_state * rng)
inlinestatic

在文件 rand_state.h 第 93 行定义.

93 {
94 lmmp_param_assert(rng != NULL);
95 mp_limb_t oldstate[2] = {rng->state[0], rng->state[1]};
96 pcg64_128_action(rng->state, rng->inc);
97
98 // XSL-RR
99 mp_limb_t xsl = ((oldstate[1]) ^ oldstate[0]);
100
101 mp_byte_t rot = (mp_byte_t)(oldstate[1] >> 58);
102 return (xsl >> rot) | (xsl << ((-rot) & 63));
103}
uint8_t mp_byte_t
定义 lmmp.h:91
uint64_t mp_limb_t
定义 lmmp.h:92
#define lmmp_param_assert(x)
定义 lmmp.h:509
mp_limb_t state[2]
static void pcg64_128_action(mp_limb_t state[2], const mp_limb_t inc[2])

引用了 pcg64_128_state::inc, LMMP_INLINE, lmmp_param_assert, lmmp_pcg64_128_random(), pcg64_128_action() , 以及 pcg64_128_state::state.

被这些函数引用 lmmp_pcg64_128_random() , 以及 lmmp_seed_random_().

函数调用图:
这是这个函数的调用关系图:

◆ lmmp_pcg64_128_srandom()

void lmmp_pcg64_128_srandom ( pcg64_128_state * rng,
mp_limb_t seed )
inlinestatic

在文件 rand_state.h 第 82 行定义.

82 {
83 lmmp_param_assert(rng != NULL);
84
85 rng->state[0] = lmmp_seed_generator(seed);
86 rng->state[1] = mix64(seed);
87 rng->inc[0] = mix64(seed + 0x9e3779b97f4a7c15ULL);
88 rng->inc[0] |= 1ull;
89 rng->inc[1] = lmmp_seed_generator(seed * 11154045850622628491ULL);
90}
static mp_limb_t lmmp_seed_generator(mp_limb_t seed)
种子生成器
static mp_limb_t mix64(mp_limb_t h)

引用了 pcg64_128_state::inc, LMMP_INLINE, lmmp_param_assert, lmmp_pcg64_128_srandom(), lmmp_seed_generator(), mix64() , 以及 pcg64_128_state::state.

被这些函数引用 lmmp_pcg64_128_srandom() , 以及 lmmp_seed_random_().

函数调用图:
这是这个函数的调用关系图:

◆ lmmp_randlimb_()

mp_limb_t lmmp_randlimb_ ( void )

依据全局状态获取单个随机limb(0 - B 均匀分布)

返回
随机limb
注解
每调用一次将会重置全局随机状态

在文件 mprand.c 第 43 行定义.

43 {
46 return ret;
47}
static __thread lmmp_global_rng_t lmmp_global_rng

引用了 lmmp_global_rng, lmmp_randlimb_(), lmmp_seed_generator(), mix64() , 以及 lmmp_global_rng_t::state.

被这些函数引用 ipn_notrial_i_() , 以及 lmmp_randlimb_().

函数调用图:
这是这个函数的调用关系图:

◆ lmmp_seed_generator()

mp_limb_t lmmp_seed_generator ( mp_limb_t seed)
inlinestatic

种子生成器

参数
seed低熵种子
返回
高熵种子

在文件 rand_state.h 第 53 行定义.

53 {
54 mp_limb_t z = (seed += 0x9e3779b97f4a7c15);
55 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
56 z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
57 return z ^ (z >> 31);
58}

引用了 LMMP_INLINE , 以及 lmmp_seed_generator().

被这些函数引用 lmmp_global_rng_init_(), lmmp_pcg64_128_srandom(), lmmp_randlimb_(), lmmp_random_(), lmmp_seed_generator(), lmmp_strong_rng_extern_(), lmmp_strong_rng_init_() , 以及 pcg64_le_seq_next().

函数调用图:
这是这个函数的调用关系图:

◆ lmmp_xoshiro256pp_random()

mp_limb_t lmmp_xoshiro256pp_random ( xoshiro256pp_state * rng)
inlinestatic

在文件 rand_state.h 第 105 行定义.

105 {
106 lmmp_param_assert(rng != NULL);
107 const mp_limb_t r = rotl(rng->s[0] + rng->s[3], 23) + rng->s[0];
108 const mp_limb_t t = rng->s[1] << 17;
109
110 rng->s[2] ^= rng->s[0];
111 rng->s[3] ^= rng->s[1];
112 rng->s[1] ^= rng->s[2];
113 rng->s[0] ^= rng->s[3];
114 rng->s[2] ^= t;
115 rng->s[3] = rotl(rng->s[3], 45);
116
117 return r;
118}
#define t
static mp_limb_t rotl(const mp_limb_t x, int k)

引用了 LMMP_INLINE, lmmp_param_assert, lmmp_xoshiro256pp_random(), rotl(), xoshiro256pp_state::s , 以及 t.

被这些函数引用 lmmp_seed_random_() , 以及 lmmp_xoshiro256pp_random().

函数调用图:
这是这个函数的调用关系图:

◆ lmmp_xoshiro256pp_srandom()

void lmmp_xoshiro256pp_srandom ( xoshiro256pp_state * rng,
mp_limb_t seed )
inlinestatic

在文件 rand_state.h 第 120 行定义.

120 {
121 lmmp_param_assert(rng != NULL);
122
123 const mp_limb_t C = 0x9e3779b97f4a7c15ULL;
124
125 rng->s[0] = mix64(seed + 0 * C);
126 rng->s[1] = mix64(seed + 1 * C);
127 rng->s[2] = mix64(seed + 2 * C);
128 rng->s[3] = mix64(seed + 3 * C);
129 // 由于mix64为双射,故不可能为全零状态
130}
#define C

引用了 C, LMMP_INLINE, lmmp_param_assert, lmmp_xoshiro256pp_srandom(), mix64() , 以及 xoshiro256pp_state::s.

被这些函数引用 lmmp_seed_random_() , 以及 lmmp_xoshiro256pp_srandom().

函数调用图:
这是这个函数的调用关系图:

◆ mix64()

mp_limb_t mix64 ( mp_limb_t h)
inlinestatic

在文件 rand_state.h 第 60 行定义.

60 {
61 h ^= h >> 33;
62 h *= 0xc2b2ae3d27d4eb4fULL;
63 h ^= h >> 29;
64 h *= 0x165667b19e3779f9ULL;
65 h ^= h >> 32;
66 return h;
67}

引用了 LMMP_INLINE , 以及 mix64().

被这些函数引用 lmmp_pcg64_128_srandom(), lmmp_randlimb_(), lmmp_random_(), lmmp_strong_rng_extern_(), lmmp_strong_rng_init_(), lmmp_xoshiro256pp_srandom(), mix64() , 以及 pcg64_le_seq_init().

函数调用图:
这是这个函数的调用关系图:

◆ pcg64_128_action()

void pcg64_128_action ( mp_limb_t state[2],
const mp_limb_t inc[2] )
inlinestatic

在文件 rand_state.h 第 69 行定义.

69 {
70 // state = (state * PCG64_MULT + inc) mod 2^128
71 // state * M = s0*m0 + ((s0*m1 + s1*m0) mod 2^64) << 64 (mod 2^128)
72 // 交叉项 s0*m1 与 s1*m0 只有低 64 位落在 2^128 以内,高 64 位模掉
73 mp_limb_t tmp[2] = {0, 0};
75 tmp[1] += state[1] * PCG128_DEFAULT_MULTIPLIER_LO;
76 tmp[1] += state[0] * PCG128_DEFAULT_MULTIPLIER_HI;
77 state[0] = tmp[0] + inc[0];
78 mp_limb_t c = state[0] < inc[0] ? 1 : 0;
79 state[1] = tmp[1] + inc[1] + c;
80}
static void _umul64to128_(uint64_t a, uint64_t b, uint64_t *low, uint64_t *high)
#define tmp
#define PCG128_DEFAULT_MULTIPLIER_HI
#define PCG128_DEFAULT_MULTIPLIER_LO

引用了 _umul64to128_(), LMMP_INLINE, PCG128_DEFAULT_MULTIPLIER_HI, PCG128_DEFAULT_MULTIPLIER_LO, pcg64_128_action() , 以及 tmp.

被这些函数引用 lmmp_pcg64_128_random() , 以及 pcg64_128_action().

函数调用图:
这是这个函数的调用关系图:

◆ pcg64_le_action()

mp_limb_t pcg64_le_action ( mp_limb_t *restrict state)
inlinestatic

在文件 rand_state.h 第 153 行定义.

153 {
154 mp_limb_t old_state = *state;
155 *state = old_state * PCG64_LE_MULTIPLIER + PCG64_LE_INCREMENT;
156
157 // RXS-M-XS
158 mp_limb_t x = old_state;
159 int count = x >> 59;
160 x ^= x >> (5 + count);
161 x *= 12605985483714917081ULL;
162 x ^= x >> 43;
163
164 return x;
165}
#define PCG64_LE_INCREMENT
#define PCG64_LE_MULTIPLIER

引用了 LMMP_INLINE, pcg64_le_action(), PCG64_LE_INCREMENT, PCG64_LE_MULTIPLIER , 以及 restrict.

被这些函数引用 pcg64_le_action() , 以及 pcg64_le_seq_next().

函数调用图:
这是这个函数的调用关系图:

◆ pcg64_le_seq_init()

void pcg64_le_seq_init ( pcg64_le_seq_t * rng,
mp_size_t i,
mp_limb_t seed )
inlinestatic

在文件 rand_state.h 第 140 行定义.

140 {
141 lmmp_param_assert(rng != NULL);
142 lmmp_param_assert(rng->k > 0);
143 lmmp_param_assert(rng->state != NULL);
144
145 mp_limb_t s;
146
147 for (; i < rng->k; i++) {
148 s = seed + i * 11154045850622628491ULL;
149 rng->state[i] = mix64(s);
150 }
151}
#define s
mp_limb_t *restrict state

引用了 pcg64_le_seq_t::k, LMMP_INLINE, lmmp_param_assert, mix64(), pcg64_le_seq_init(), s , 以及 pcg64_le_seq_t::state.

被这些函数引用 lmmp_strong_rng_extern_(), lmmp_strong_rng_init_() , 以及 pcg64_le_seq_init().

函数调用图:
这是这个函数的调用关系图:

◆ pcg64_le_seq_next()

void pcg64_le_seq_next ( mp_ptr restrict dst,
mp_size_t n,
pcg64_le_seq_t * rng )
inlinestatic

在文件 rand_state.h 第 167 行定义.

167 {
168 lmmp_param_assert(dst != NULL);
169 lmmp_param_assert(rng != NULL);
171 mp_size_t i;
173 for (i = 0; i + 3 < n; i += 4) {
174 dst[i + 0] = pcg64_le_action(&rng->state[i + 0]) ^ mixn;
175 dst[i + 1] = pcg64_le_action(&rng->state[i + 1]) ^ mixn;
176 dst[i + 2] = pcg64_le_action(&rng->state[i + 2]) ^ mixn;
177 dst[i + 3] = pcg64_le_action(&rng->state[i + 3]) ^ mixn;
178 }
179 for (; i < n; i++) {
180 dst[i] = pcg64_le_action(&rng->state[i]) ^ mixn;
181 }
182 for (; i < rng->k; i++) {
183 mp_limb_t old_state = rng->state[i];
184 rng->state[i] = old_state * PCG64_LE_MULTIPLIER + PCG64_LE_INCREMENT;
185 }
186}
#define k
uint64_t mp_size_t
定义 lmmp.h:93
#define n
static mp_limb_t pcg64_le_action(mp_limb_t *restrict state)

引用了 k, pcg64_le_seq_t::k, LMMP_INLINE, lmmp_param_assert, lmmp_seed_generator(), n, pcg64_le_action(), PCG64_LE_INCREMENT, PCG64_LE_MULTIPLIER, pcg64_le_seq_next(), restrict , 以及 pcg64_le_seq_t::state.

被这些函数引用 lmmp_strong_random_() , 以及 pcg64_le_seq_next().

函数调用图:
这是这个函数的调用关系图:

◆ rotl()

mp_limb_t rotl ( const mp_limb_t x,
int k )
inlinestatic

在文件 rand_state.h 第 43 行定义.

43 {
44 const int shift = k & 63;
45 return (x << shift) | (x >> ((-shift) & 63));
46}

引用了 k, LMMP_INLINE , 以及 rotl().

被这些函数引用 lmmp_xoshiro256pp_random() , 以及 rotl().

函数调用图:
这是这个函数的调用关系图: