Exemplo n.º 1
0
Arquivo: well.c Projeto: PhDP/bogosort
double well_double(well *rng) {
  unsigned int *const state = rng->state;
  const unsigned int state_n = rng->state_n;
  const unsigned int z1 = WELL_IDEN(state[state_n]) ^ WELL_MAT3POS(8, state[(state_n + 3) & 0x0000001fUL]);
  const unsigned int z2 = WELL_MAT3NEG(-19, state[(state_n+24) & 0x0000001fUL]) ^ WELL_MAT3NEG(-14, state[(state_n + 10) & 0x0000001fUL]);
  state[state_n] = z1 ^ z2;
  state[(state_n + 31) & 0x0000001fUL] = WELL_MAT3NEG(-11, (state[(state_n + 31) & 0x0000001fUL])) ^ WELL_MAT3NEG(-7, z1) ^ WELL_MAT3NEG(-13, z2);
  rng->state_n = (state_n + 31) & 0x0000001fUL;
  return ((double)state[rng->state_n] * 2.32830643653869628906e-10);
}
Exemplo n.º 2
0
double well1024_unif_rand(well1024 *prng)
{
    unsigned int *state, state_n, z0, z1, z2;

    state = prng->state;
    state_n = prng->state_n;
    z0 = state[(state_n + 31) & 0x0000001FUL];
    z1 = state[state_n] ^ WELL_MAT3POS(8, state[(state_n + 3) & 0x0000001FUL]);
    z2 = WELL_MAT3NEG(-19, state[(state_n + 24) & 0x0000001FUL]) ^
         WELL_MAT3NEG(-14, state[(state_n + 10) & 0x0000001FUL]);
    state[state_n] = z1 ^ z2;
    state[(state_n + 31) & 0x0000001FUL] = WELL_MAT3NEG(-11, z0) ^
                                           WELL_MAT3NEG( -7, z1) ^
                                           WELL_MAT3NEG(-13, z2);
    prng->state_n = (state_n + 31) & 0x0000001FUL;

    return ((double) state[prng->state_n] * 2.32830643653869628906E-10);
}