i have an assignment :
to solve this I wrote this code:
a1q1 <- function(n, j, k, m, seed){
x_0=seed
set_1=c(x_0)
for (l in 1:k) {
set_1[l+1]=(1103515245*set_1[l]+12345)%%2^32
}
for (f in 1:n) {
set_1[k+1+f]=(set_1[f-j+k+1]+set_1[f+1])%%m
}
return(set_1[k+2:length(set_1)])
}
a1q1(sample(200:300,1),36,99,2^30,202)
sad returns me NA values and I don't understand why. Would be happy for help , was trying to figure out the problem for hours.
This is the output:
tried to write my code but seems to be producing only NA
.
i also have some test to check my code :
# Q1
# Checks that the code for "a1q1" produces a numeric vector
# of length n
n <- sample(200:300,1)
j <- 36
k <- 99
m <- 2^(30)
seed <- 2022
X <- a1q1(n,j,k,m,seed)
if((length(X) != n) | (!is.numeric(X))){
stop("a1q2 does not produce a vector of length n of integers")
}
gives back"does not produce a vector of length n of integers"