Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Random-numbers/FreeBASIC/random-numbers.basic
Normal file
36
Task/Random-numbers/FreeBASIC/random-numbers.basic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Const pi As Double = 3.141592653589793
|
||||
Randomize
|
||||
|
||||
' Generates normally distributed random numbers with mean 0 and standard deviation 1
|
||||
Function randomNormal() As Double
|
||||
Return Cos(2.0 * pi * Rnd) * Sqr(-2.0 * Log(Rnd))
|
||||
End Function
|
||||
|
||||
Dim r(0 To 999) As Double
|
||||
Dim sum As Double = 0.0
|
||||
|
||||
' Generate 1000 normally distributed random numbers
|
||||
' with mean 1 and standard deviation 0.5
|
||||
' and calculate their sum
|
||||
For i As Integer = 0 To 999
|
||||
r(i) = 1.0 + randomNormal/2.0
|
||||
sum += r(i)
|
||||
Next
|
||||
|
||||
Dim mean As Double = sum / 1000.0
|
||||
|
||||
Dim sd As Double
|
||||
sum = 0.0
|
||||
' Now calculate their standard deviation
|
||||
For i As Integer = 0 To 999
|
||||
sum += (r(i) - mean) ^ 2.0
|
||||
Next
|
||||
sd = Sqr(sum/1000.0)
|
||||
|
||||
Print "Mean is "; mean
|
||||
Print "Standard Deviation is"; sd
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue