dimanche 1 décembre 2019

Finding value of a simple Pseudo random number generation funciton

I have an equation to generate pseudo-random numbers, example function is well-known called Linear congruential generator(LCG). The function definition is like bellow.

R1 = (a*R0 + c) mod 23

I can easily write a recursive function to generate random number when seed value (R0) and a,c and m are given. For example

ƒunction random (n, a,r0,b,c)
{
    if(n==0) return r0;

    return (a * rand(n-1) + b) % c;
}

Here, If I want to generate 20th random number, I can call with random(20,5,3,17,23).

My question is how can I calcualte value with pen and pencil for a certain value of n, suppose n = 2019?.




Aucun commentaire:

Enregistrer un commentaire