Created
June 15, 2015 22:29
-
-
Save dewittpe/45f826d1dba22338b084 to your computer and use it in GitHub Desktop.
Random Number Generator Graphics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------------- # | |
# file: random-number-images.R | |
# author: Peter DeWitt | |
# | |
# inspired by the work presented at http://boallen.com/random-numbers.html | |
# this file generates several images based on random number generators in R | |
# ---------------------------------------------------------------------------- # | |
# ---------------------------------------------------------------------------- # | |
# libraries | |
# ---------------------------------------------------------------------------- # | |
library(ggplot2) | |
library(reshape2) | |
# ---------------------------------------------------------------------------- # | |
# data set construction | |
# ---------------------------------------------------------------------------- # | |
set.seed(42, kind = "Mersenne-Twister", normal.kind = NULL) # default | |
runif(1) | |
set.seed(42, kind = "Wichmann-Hill", normal.kind = NULL) | |
runif(1) | |
set.seed(42, kind = "Marsaglia-Multicarry", normal.kind = NULL) | |
runif(1) | |
set.seed(42, kind = "Super-Duper", normal.kind = NULL) | |
runif(1) | |
set.seed(42, kind = "Knuth-TAOCP-2002", normal.kind = NULL) | |
runif(1) | |
set.seed(42, kind = "Knuth-TAOCP", normal.kind = NULL) | |
runif(1) | |
set.seed(42, kind = "L'Ecuyer-CMRG", normal.kind = NULL) | |
runif(1) | |
# a vector of kinds | |
kinds <- c("Mersenne-Twister", # default | |
"Wichmann-Hill", | |
"Marsaglia-Multicarry", | |
"Super-Duper", | |
"Knuth-TAOCP-2002", | |
"Knuth-TAOCP", | |
"L'Ecuyer-CMRG") | |
dat <- expand.grid(rw = 1:(512 * 2), cl = 1:(512 * 2)) | |
for(k in kinds) { | |
set.seed(42, kind = k) | |
dat <- cbind(dat, as.numeric(runif(nrow(dat)) < 0.5)) | |
} | |
names(dat)[-(1:2)] <- kinds | |
dat <- melt(dat, id.vars = c("rw", "cl")) | |
ggplot(dat) + | |
aes(x=cl, y=rw, fill = factor(value)) + | |
facet_wrap( ~ variable) + | |
geom_tile() | |
# ---------------------------------------------------------------------------- # | |
# end of file | |
# ---------------------------------------------------------------------------- # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment