w <- 256L h <- 256L set.seed(0) lcg_prng <- function(n, y1, m, a, b) { if (n == 1) return(y1) res <- integer(n) res[1] <- y1 for (i in 2:n) { y1 <- (a*y1 + b) %% m res[i] <- y1 } res } m <- 2^11 z <- sample(1:m, w*h, replace=T) img_sample <- matrix(z %% 2, nrow=w) y <- lcg_prng(w*h, y1=1, m=m, a=1017, b=1) img_lcg <- matrix(y %% 2, nrow=w) par(mfrow=c(1,2), mar=c(1,1,1,1)) image( img_sample, col = c("black", "white"), axes = FALSE, useRaster = TRUE, asp=1, # fixes aspect ratio main="sample()") image( img_lcg, col = c("black", "white"), axes = FALSE, useRaster = TRUE, asp=1, main="lcg_prng()")