Consider the above quadratic residue generator xn+1 = xn2 mod m with m = 4783 × 4027. Write a program to generate pseudo-random numbers from this generator. Use this to determine the period of the generator starting with seed x0 = 196, and with seed x0 = 400?
The R program is
x={}
x0 = 196# seed
x[1]=x0
m =4783*4027
k=1 # how many next random numbers you want
for(n in 1:k){
x[n+1] =(x[n]^2)%%m
}
x
[1] 196 38416
#The Output is Seed and next random numbers
x0 = 400 # seed
x[1]=x0
m =4783*4027
k=1 # how many next random numbers you wants
for(n in 1:k){
x[n+1] =(x[n]^2)%%m
}
x
[1] 400 160000
# The output is Seed and next random numbers
x={}
x0 = 196
x[1]=x0
m =4783*4027
k=10
for(n in 1:k){
x[n+1] =(x[n]^2)%%m
}
x
[1] 196 38416 11942340 179421 6528630 11496859 16561776 4718361 [9] 17746035 3406856 543841
x0 = 400
x[1]=x0
m =4783*4027
k=10
for(n in 1:k){
x[n+1] =(x[n]^2)%%m
}
x
[1] 400 160000 1943611 13179555 2320953 1741316 15551072 3530790 [9] 12690106 11484744 14234586
Get Answers For Free
Most questions answered within 1 hours.