How to resolve the algorithm Random numbers step by step in the Visual FoxPro programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Random numbers step by step in the Visual FoxPro programming language
Table of Contents
Problem Statement
Generate a collection filled with 1000 normally distributed random (or pseudo-random) numbers with a mean of 1.0 and a standard deviation of 0.5 Many libraries only generate uniformly distributed random numbers. If so, you may use one of these algorithms.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Random numbers step by step in the Visual FoxPro programming language
Source code in the visual programming language
LOCAL i As Integer, m As Double, n As Integer, sd As Double
py = PI()
SET TALK OFF
SET DECIMALS TO 6
CREATE CURSOR gdev (deviate B(6))
RAND(-1)
n = 1000
m = 1
sd = 0.5
CLEAR
FOR i = 1 TO n
INSERT INTO gdev VALUES (GaussDev(m, 1/sd))
ENDFOR
CALCULATE AVG(deviate), STD(deviate) TO m, sd
? "Mean", m, "Std Dev", sd
SET TALK ON
SET DECIMALS TO
FUNCTION GaussDev(mean As Double, sdev As Double) As Double
LOCAL z As Double
z = SQRT(-2*LOG(RAND()))*COS(py*RAND())
IF sdev # 0
z = mean + z/sdev
ENDIF
RETURN z
ENDFUNC
You may also check:How to resolve the algorithm Infinity step by step in the Slate programming language
You may also check:How to resolve the algorithm Topological sort step by step in the Scheme programming language
You may also check:How to resolve the algorithm 24 game step by step in the Wren programming language
You may also check:How to resolve the algorithm Last letter-first letter step by step in the Clojure programming language
You may also check:How to resolve the algorithm Floyd-Warshall algorithm step by step in the Python programming language