Skip to content

Instantly share code, notes, and snippets.

@lagondo
Created February 12, 2016 19:59
Show Gist options
  • Select an option

  • Save lagondo/5d89e290bdc12348e0fd to your computer and use it in GitHub Desktop.

Select an option

Save lagondo/5d89e290bdc12348e0fd to your computer and use it in GitHub Desktop.
Random walk gaussian
const R = require('ramda')
const plot = require('plotter').plot
const randomBoolean = () => Math.random() > 0.5
const randomOneOrMinusOne = () => randomBoolean() ? 1 : -1
const randomWalk = (length) => R.times(randomOneOrMinusOne, 100)
const randomWalkEnd = (length) => R.sum(randomWalk(length))
const manyRandomWalks = R.times(() => randomWalkEnd(100), 1000000)
const distribution = R.countBy(R.identity, manyRandomWalks)
const values = R.map((x) => distribution[x], R.range(-100, 100))
plot({
data: values,
filename: 'output.png'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment