lundi 12 avril 2021

Recursion in R pseudo random numbers

I have to use recursion to produce pseudo random numbers. For fixed values a, b and c, I need to calculate: x_n+1 = (a * x_n + c) modulo 2^b. Random numbers are obtained by the function R_n = x_n / (2^b). I need to save these R_n values to make a histogram. How can I make a function in R that uses it's previous values x_n to produce x_n+1? I have made a start with my code, it's listed below.

a=5
b=4
c=3
k=10000
random <- function(x) {
  if(x<k){
    x = (a*x+c)%%2^b
    k++
  }
}



Aucun commentaire:

Enregistrer un commentaire