LMMC
Lamina Mathematic core
载入中...
搜索中...
未找到
random_internal.h
浏览该文件的文档.
1#ifndef LMMC_RANDOM_INTERNAL_H
2#define LMMC_RANDOM_INTERNAL_H
3
4#include <stdint.h>
5#include "lmmc/random.h"
6
7struct lmmc_rng_t {
8 uint64_t state[4];
9};
10static inline uint64_t rotl(const uint64_t x, int k) {
11 return (x << k) | (x >> (64 - k));
12}
13
14static inline uint64_t xoshiro256ss_next(uint64_t* s) {
15 const uint64_t result = rotl(s[1] * 5, 7) * 9;
16 const uint64_t t = s[1] << 17;
17
18 s[2] ^= s[0];
19 s[3] ^= s[1];
20 s[1] ^= s[2];
21 s[0] ^= s[3];
22
23 s[2] ^= t;
24 s[3] = rotl(s[3], 45);
25
26 return result;
27}
28
29static inline double u64_to_double01(uint64_t x) {
30 return (double)(x >> 11) * (1.0 / 9007199254740992.0);
31}
32
33double lmmc_rng_standard_normal(uint64_t* state);
34
35#endif
伪随机数发生器与常用分布。
double lmmc_rng_standard_normal(uint64_t *state)
用 256 层 Ziggurat 采样标准正态:先采样 |x|,再随机赋予符号。
uint64_t state[4]
随机数发生器(不透明类型)。