Skip to content

Instantly share code, notes, and snippets.

@pitakakariki
Last active September 23, 2015 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pitakakariki/4195637ba88af198f01b to your computer and use it in GitHub Desktop.
Save pitakakariki/4195637ba88af198f01b to your computer and use it in GitHub Desktop.
Flag Referendum PRNG
f <- function(v=1000000, x=9, y=1) list(x=x, y=y, z=(v + 1000*(v %% 10)) %% 30323)
g <- function(x, y, z, rc) {
x <- (171 * x) %% 30269
y <- (172 * y) %% 30307
z <- (170 * z) %% 30323
rc <- ((10000 * x) %/% 30269) + ((10000 * y) %/% 30307) + ((10000 * x) %/% 30323)
list(x=x, y=y, z=z, rc=rc)
}
h <- function(...) {
rval <- integer(201)
w <- f(...)
for(i in 1:5) w <- do.call(g, w)
rval[1] <- w$rc
for(i in 1:200) {
w <- do.call(g, w)
rval[i+1] <- w$rc
}
return(rval)
}
length(unique(h(x=9)))
# 199
length(unique(h(x=10)))
# 201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment