Skip to content

Instantly share code, notes, and snippets.

@clauswilke
Created March 7, 2022 03:41
Show Gist options
  • Select an option

  • Save clauswilke/6d10f1d58fb3da62da9057b418fa191c to your computer and use it in GitHub Desktop.

Select an option

Save clauswilke/6d10f1d58fb3da62da9057b418fa191c to your computer and use it in GitHub Desktop.

Revisions

  1. clauswilke created this gist Mar 7, 2022.
    30 changes: 30 additions & 0 deletions normal.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    # 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])