Skip to content

Instantly share code, notes, and snippets.

@jacky860226
Created April 25, 2016 07:25
Show Gist options
  • Save jacky860226/3706aa308b6c7b969bbf42050147a5f4 to your computer and use it in GitHub Desktop.
Save jacky860226/3706aa308b6c7b969bbf42050147a5f4 to your computer and use it in GitHub Desktop.
Lehmer Random Number Generator
//線性同餘方法
//這個方法數字很好記
unsigned random1(){
static unsigned x=20150118;
return x=x*0xdefaced+1;
}
int random2(){
static unsigned x=time(0);
return x=x*16807;//7^5
}
// 網路上看到的,用來處理treap的亂數
int random3(){
static int x=123456789;
return x+=(x<<2)+1;
}
long long random4(){
static long long x=323232;
return x+=x<<2|1;
}
//5、6是較快的算法,利用簡單的移位處理
inline int random5(){
static int seed=20160424;
return seed+=(seed<<16)+0x1db3d743;
}
inline long long random6(){
static long long seed=20160424;
return seed+=(seed<<32)+0xdb3d742c265539d;
}
//要記數字太麻煩了而且比較慢,比賽時不要用這種
int random7(){
static int x=1;
return x=x*1103515245+12345;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment