簡易な長周期擬似乱数の合成手法

| ← back |
| home |

JPL sequence (JPL code) とその応用
//-----------------------------------------------------------------
// long period random number generater, return value = 0/1

unsigned char mix_rand(void) {
  return mseq13(0)^mseq17(0)^mseq19(0)^mseq31(0)^mseq61(0)^xorshift(0);
}

//-----------------------------------------------------------------
// 32bit long period random number generater

uint32_t mix_rand32bit(void) {
  uint32_t rnd;
  unsigned i;

  rnd=0;
  for (i=0; i<32; i=i+1) {
    rnd=(rnd<<1)|(mseq13(0)^mseq17(0)^mseq19(0)^mseq31(0)^mseq61(0));
  }
  rnd=rnd^xorshift32bit(0);
  return rnd;
}

//-----------------------------------------------------------------
// 64bit long period random number generater

uint64_t mix_rand64bit(void) {
  uint64_t rnd;
  unsigned i;

  rnd=0;
  for (i=0; i<64; i=i+1) {
    rnd=(rnd<<1)|(mseq13(0)^mseq17(0)^mseq19(0)^mseq31(0)^mseq61(0));
  }
  rnd=rnd^xorshift64bit(0);
  return rnd;
}

//-----------------------------------------------------------------

| ← back | ↑top |

| home |