Skip to content

Instantly share code, notes, and snippets.

@victusfate
Created September 10, 2019 18:13
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 victusfate/80ff7083d01f0f51d25eb42056b85f9c to your computer and use it in GitHub Desktop.
Save victusfate/80ff7083d01f0f51d25eb42056b85f9c to your computer and use it in GitHub Desktop.
a weird way to roll dice
const d = (dv) => Math.floor(Math.random()*dv)
const sum = (sum,dv) => sum + d(dv)
const r = (n,dv) => Array.from({length:n}).map(x => dv).reduce(sum)
console.log('roll 8d12',r(8,12),'average',8 * 6.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment