Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
Created September 21, 2022 17:45
Show Gist options
  • Save hjroh0315/1160a621198754798dae7ae270a74679 to your computer and use it in GitHub Desktop.
Save hjroh0315/1160a621198754798dae7ae270a74679 to your computer and use it in GitHub Desktop.
xorshift32 (usable with std::shuffle and more)
#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