Published
Edited
Jun 17, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function randomPoisson(lambda) {
var Exp = d3r.randomExponential(1);
return function() {
var acc = 0, l = lambda;
while (l > 16) {
var n = Math.floor(0.875 * l),
t = randomGamma(n, 1)();
if (t > l) {
return acc + randomBinomial(n - 1, l / t)();
}
acc += n;
l -= t;
}
for (var s = Exp(), k = 0; s <= l; ++k) s += Exp();
return acc + k;
};
}
Insert cell
Insert cell
// times in milliseconds
[timefunc(randomPoissonSimple(100)), timefunc(randomPoisson(100)), timefunc(randomPoisson(1e12))]
Insert cell
function timefunc(f) {
var start = performance.now(),
A = Array.from({length: 100000}, f),
end = performance.now();
return end - start;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more