### Demonstrate the performance of the RandU algorithm. # generate uniform random numbers according the RandU algorithm nSeed <- 1 nLength <- 10000 a <- 65539 m <- 2^(31) res <- numeric(nLength) res[1] <- nSeed for (i in 2:nLength) { res[i] <- (a*res[i-1])%%m } # normalize the output res <- res/m # plot histgram -> looks random hist(res) # plot pairs (x_k, x_k+1) -> looks sufficiently random mPairs <- cbind(res[-length(res)], res[-1]) plot(mPairs,cex=0.1) # plot triples (x_k, x_k+1, x_k+2) -> there is a deterministic relation (see lecture) library(rgl) mTriples <- cbind(res[-c(length(res)-1,length(res))], res[-c(1,length(res))], res[-c(1,2)]) plot3d(mTriples,cex=0.1)