2016-11-10 24 views
1

this codePCG RNG中inc变量的含义是什么?

// *Really* minimal PCG32 code/(c) 2014 M.E. O'Neill/pcg-random.org 
// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) 

typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t; 

uint32_t pcg32_random_r(pcg32_random_t* rng) 
{ 
    uint64_t oldstate = rng->state; 
    // Advance internal state 
    rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1); 
    // Calculate output function (XSH RR), uses old state for max ILP 
    uint32_t xorshifted = ((oldstate >> 18u)^oldstate) >> 27u; 
    uint32_t rot = oldstate >> 59u; 
    return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); 
} 

什么是rng->inc点?据我所知,它永远不会被写入。

回答

1

我认为这是一个种子流选择器,准确的说。看看在code on GitHub,尤其是pcg32_srandom_r功能:

// pcg32_srandom(initstate, initseq) 
// pcg32_srandom_r(rng, initstate, initseq): 
//  Seed the rng. Specified in two parts, state initializer and a 
//  sequence selection constant (a.k.a. stream id) 

void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq) 
{ 
    rng->state = 0U; 
    rng->inc = (initseq << 1u) | 1u; 
    pcg32_random_r(rng); 
    rng->state += initstate; 
    pcg32_random_r(rng); 
} 

有更多关于the PCG website流。

+0

啊我明白了,所以如果你想要几个不同的PRN序列,但是想把它们称为#1,#2,#3等......谢谢! – Timmmm