Created
September 21, 2022 17:45
-
-
Save hjroh0315/1160a621198754798dae7ae270a74679 to your computer and use it in GitHub Desktop.
xorshift32 (usable with std::shuffle and more)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
using u32=uint32_t; | |
struct xorshift32_gen | |
{ | |
const u32 default_seed = 1; | |
u32 cur; | |
using result_type=u32; | |
xorshift32_gen():cur(default_seed){} | |
xorshift32_gen(u32 sd):cur(sd){} | |
void seed(u32 sd){cur=sd;} | |
constexpr static u32 min(){return 1;} | |
constexpr static u32 max(){return 4294967295;} | |
u32 operator()() | |
{ | |
u32 tmp=cur; | |
cur^=cur<<13; | |
cur^=cur>>17; | |
cur^=cur<<5; | |
return tmp; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment