【模板】伪随机数生成器

#include<bits/stdc++.h>
using namespace std;
#define random(a,b) ((a)+Curl_rand()%((b)-(a)+1))
static unsigned int randseed;
int n,cnt;
unsigned int Curl_rand(void)
{
  unsigned int r;
  /* 返回一个无符号32位整型的伪随机数. */
  r = randseed = randseed * 1103515245 + 12345;
  return (r << 16) | ((r >> 16) & 0xFFFF);
}

void Curl_srand(void)
{
  /* 产生随机的伪随机数序列。 */
  randseed = (unsigned int) time(NULL);
  Curl_rand();
  Curl_rand();
  Curl_rand();
}
int main() {
    Curl_srand();
}

posted @ 2019-02-13 11:59  Greenty  阅读(491)  评论(0编辑  收藏  举报