Skip to content

Instantly share code, notes, and snippets.

@wraithan
Created July 27, 2014 03:45
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 wraithan/c42b0a69f697b3e0aa33 to your computer and use it in GitHub Desktop.
Save wraithan/c42b0a69f697b3e0aa33 to your computer and use it in GitHub Desktop.
Test every second looking for a sample every 6 minutes on average
var hard_min = 60
var target = 360
var hard_max = target*2
var samples = 1e7
function test(multiplier) {
var data = []
var period = target * multiplier
var min = hard_max
var max = hard_min
var i = hard_min
while (data.length < samples) {
i += 1
if (Math.random() < i/period) {
data.push(i)
if (i < min) {
min = i
}
if (i > max) {
max = i
}
i = 0
} else if (i === hard_max) {
data.push(i)
i = 0
}
}
var total = data.reduce(function (a, b) {
return a + b
}, 0)
console.log(min, max, data.slice(0,20))
return total/data.length
}
var last = 0
var i = 235
var interval = 0.1
while (last < 361) {
last = test(i)
console.log(i, last)
i += interval
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment