Skip to content

Instantly share code, notes, and snippets.

@clauswilke
Created March 7, 2022 03:41
Show Gist options
  • Save clauswilke/6d10f1d58fb3da62da9057b418fa191c to your computer and use it in GitHub Desktop.
Save clauswilke/6d10f1d58fb3da62da9057b418fa191c to your computer and use it in GitHub Desktop.
Deterministically generated normal variates
# Deterministically generated normal variates, implemented here in R but more
# useful for GLSL programming.
library(ggplot2)
fract <- function(x) x - floor(x)
rand <- function(x) fract(3482954.234 * sin(24934.342 * x + 12394.32))
norm <- function(x) {
(rand(x) + rand(x + 17) + rand(x + 234) + rand(x + 456) +
rand(x + 542) + rand(x + 586) + rand(x + 601) + rand(x + 723) +
rand(x + 869) + rand(x + 901) + rand(x + 932) + rand(x + 998)
- 6)
}
df <- data.frame(
x = norm(1:10000),
y = norm(10001:20000)
)
df2 <- data.frame(
x = rnorm(10000),
y = rnorm(10000)
)
ggplot(df, aes(x, y)) + geom_point(size = .1) + theme_bw()
ggplot(df2, aes(x, y)) + geom_point(size = .1) + theme_bw()
shapiro.test(df$x[1:4000])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment