Skip to content

Instantly share code, notes, and snippets.

@jdh30
Last active January 4, 2016 15:19
Show Gist options
  • Save jdh30/8639742 to your computer and use it in GitHub Desktop.
Save jdh30/8639742 to your computer and use it in GitHub Desktop.
module SciMark2
module Random =
let m = Array.create 17 0
let mutable i = 4
let mutable j = 16
let mdig = 32
let m1 = (1 <<< mdig - 2) + ((1 <<< mdig - 2) - 1)
let m2 = 1 <<< mdig / 2
let dm1 = 1.0 / float m1
do
let seed = 101010
let jseed = min (abs seed) m1;
let mutable jseed = if jseed &&& 1 = 0 then jseed - 1 else jseed
let k0 = 9069 % m2
let k1 = 9069 / m2
let mutable j0 = jseed % m2
let mutable j1 = jseed / m2
for i=0 to 16 do
jseed <- j0 * k0
j1 <- (jseed / m2 + j0 * k1 + j1 * k0) % (m2 / 2)
j0 <- jseed % m2
m.[i] <- j0 + m2 * j1
i <- 4
j <- 16
let inline NextDouble() =
let mutable k = m.[i] - m.[j]
if k < 0 then k <- k + m1
m.[j] <- k
i <- if i = 0 then 16 else i - 1
j <- if j = 0 then 16 else j - 1
dm1 * float k
module MonteCarlo =
let flops n = 4 * n
let exec n =
let sqr x = x * x
let mutable c = 0
for i=1 to n do
if sqr(Random.NextDouble()) + sqr(Random.NextDouble()) <= 1. then
c <- c + 1
4. * float c / float n
MonteCarlo.exec 100000000
|> printfn "%0.15f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment