Skip to content

Instantly share code, notes, and snippets.

@funwithtriangles
Created March 9, 2020 02:39
Embed
What would you like to do?
random fibonacci sequence
const viswanath = 1.1319882487943
const numTurns = 5000
const posNeg = () => Math.random() > 0.5 ? 1 : -1
let prev = 1
let curr = 1
let temp
for (let i = 0; i < numTurns; i++) {
temp = curr
curr = curr + prev * posNeg()
prev = temp
console.log(curr)
}
const ratio = Math.pow(Math.abs(curr), 1/numTurns)
console.log(`
Number of turns: ${numTurns}
Ratio: ${ratio}
Viswanath: ${viswanath}
`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment