开发者

Random Number Generation with Well44497a in C++

Sorry to bother again, but as I am new C++ I am having a lot of weird and silly problems.

I am programing a MCMC method. I read in this forum that the WELL RNG was a good alternative to generate random numbers so I am trying to make it work. So here the questions:

  1. I am compiling the "Well44497a.c" within my c++ project without further modifications. It compiled. Is that right or should I make any change?

  2. I am using the following scheme inside my code but it is just generating a cycle of 3 RN

SOLVED: The problem was that InitWELLRNG44497a(state) should be placed outside the function. I was re initiating the generator every开发者_如何学C time I was generating a sample. For the whole run the generator has to be initialized just once.

    int* sampler(PARAMETERS) { //this function returns a sample

    int k;

    unsigned int state[1391];

    for (k = 0; k < 1391; ++k) 
    {
        state[k] = k;
    }

    InitWELLRNG44497a(state); //THIS SHOULD GO ON THE CALLER FUNCTION NOT HERE

    double value_first = valuate(first_state); // this function valuates one of two possible states
    double value_second = valuate(second_state); 

    double rand_number = WELLRNG44497a()

    if(rand_number > value_first / (value_first + value_second))
       return second_state;
    else
       return first_state;
    }        


Your function appears to initialise the state array with the same values every time you call your sampler() function. The idea of the state array is that it holds the current state of the random number generator, and that you don't fiddle with the contents of state between calls to the RNG.

Make the state array global in your program, initialise it once, and don't touch it after initialisation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜