Skip to content

Instantly share code, notes, and snippets.

@osuushi
Forked from peterc/pi.js
Last active December 14, 2015 03:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osuushi/5022143 to your computer and use it in GitHub Desktop.
Save osuushi/5022143 to your computer and use it in GitHub Desktop.
var points_total = 0;
var points_inside = 0;
var x, y, i;
while(true) {
for(i = 0; i < 10000; i++) {
x = Math.random();
y = Math.random();
points_inside += 2 + ~(x*x + y*y);
}
points_total += i;
console.log(points_inside + "/" + points_total + " pi == " + (4 * points_inside / points_total));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment