伪随机数
next = 1;function rand() // 生成伪随机数{next = next * 1103515245 + 12345;return (next / 65536) % 32768;}function srand(seed) // 修改种子{next = seed;}srand(Date.now()); rand()
MWC1616:
uint32_t state0 = 1;uint32_t state1 = 2;uint32_t mwc1616() {state0 = 18030 * (state0 & 0xFFFF) + (state0 >> 16);state1 = 30903 * (state1 & 0xFFFF) + (state1 >> 16);return state0 << 16 + (state1 & 0xFFFF);}
uint64_t state0 = 1;uint64_t state1 = 2;uint64_t xorshift128plus() {uint64_t s1 = state0;uint64_t s0 = state1;state0 = s0;s1 ^= s1 << 23;s1 ^= s1 >> 17;s1 ^= s0;s1 ^= s0 >> 26;state1 = s1;return state0 + state1;}