Monte Carlo methods: Difference between revisions
Content added Content deleted
(Updated to work with Nim 1.4: added missing parameter type, added "import random", changed "random" to "rand".) |
(Added Quackery.) |
||
Line 2,033: | Line 2,033: | ||
print np.sum(np.random.rand(n)**2+np.random.rand(n)**2<1)/float(n)*4 |
print np.sum(np.random.rand(n)**2+np.random.rand(n)**2<1)/float(n)*4 |
||
</lang> |
</lang> |
||
=={{header|Quackery}}== |
|||
{{trans|Forth}} |
|||
<lang Quackery> [ $ "bigrat.qky" loadfile ] now! |
|||
[ [ 64 bit ] constant |
|||
dup random dup * |
|||
over random dup * + |
|||
swap dup * < ] is hit ( --> b ) |
|||
[ 0 swap times |
|||
[ hit if 1+ ] ] is sims ( n --> n ) |
|||
[ dup echo say " trials " |
|||
dup sims 4 * |
|||
swap 20 point$ echo$ cr ] is trials ( n --> ) |
|||
' [ 10 100 1000 10000 100000 1000000 ] witheach trials</lang> |
|||
{{out}} |
|||
<pre>10 trials 2.8 |
|||
100 trials 3.2 |
|||
1000 trials 3.172 |
|||
10000 trials 3.1484 |
|||
100000 trials 3.1476 |
|||
1000000 trials 3.142256</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |