2016-11-10 61 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