Monte Carlo methods: Difference between revisions
Content deleted Content added
Added Sidef |
m →{{header|JavaScript}}: (minor normalisation of spacing – with JS beautify) |
||
Line 923: | Line 923: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
<lang JavaScript>function mcpi(n){ |
<lang JavaScript>function mcpi(n) { |
||
var x,y,m=0; |
var x, y, m = 0; |
||
for(var i = 0; i < n; i += 1) { |
for (var i = 0; i < n; i += 1) { |
||
x = Math.random(); |
x = Math.random(); |
||
y = Math.random(); |
y = Math.random(); |
||
if (x*x + y*y < 1) { |
if (x * x + y * y < 1) { |
||
m += 1; |
|||
⚫ | |||
} |
|||
⚫ | |||
return 4*m/n; |
return 4 * m / n; |
||
} |
} |
||
Line 947: | Line 949: | ||
3.1417656 |
3.1417656 |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |