Random numbers: Difference between revisions
Content added Content deleted
(Dialects of BASIC moved to the BASIC section.) |
(→{{header|Chipmunk Basic}}: Added.) |
||
Line 217: | Line 217: | ||
<pre>Mean = 1.01848064 |
<pre>Mean = 1.01848064 |
||
Standard deviation = 0.503551814</pre> |
Standard deviation = 0.503551814</pre> |
||
==={{header|Chipmunk Basic}}=== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="basic"> |
|||
10 ' Random numbers |
|||
20 randomize timer |
|||
30 dim r(999) |
|||
40 sum = 0 |
|||
50 for i = 0 to 999 |
|||
60 r(i) = 1+randomnormal()/2 |
|||
70 sum = sum+r(i) |
|||
80 next |
|||
90 mean = sum/1000 |
|||
100 sum = 0 |
|||
110 for i = 0 to 999 |
|||
120 sum = sum+(r(i)-mean)^2 |
|||
130 next |
|||
140 sd = sqr(sum/1000) |
|||
150 print "Mean is ";mean |
|||
160 print "Standard Deviation is ";sd |
|||
170 print |
|||
180 end |
|||
500 sub randomnormal() |
|||
510 randomnormal = cos(2*pi*rnd(1))*sqr(-2*log(rnd(1))) |
|||
520 end sub |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
Two runs. |
|||
<pre> |
|||
Mean is 1.007087 |
|||
Standard Deviation is 0.496848 |
|||
</pre> |
|||
<pre> |
|||
Mean is 0.9781 |
|||
Standard Deviation is 0.508147 |
|||
<pre> |
|||
==={{header|Commodore BASIC}}=== |
==={{header|Commodore BASIC}}=== |