How to resolve the algorithm Random numbers step by step in the ReScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Random numbers step by step in the ReScript 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 ReScript programming language
Source code in the rescript programming language
let pi = 4.0 *. atan(1.0)
let random_gaussian = () => {
1.0 +.
sqrt(-2.0 *. log(Random.float(1.0))) *.
cos(2.0 *. pi *. Random.float(1.0))
}
let a = Belt.Array.makeBy(1000, (_) => random_gaussian ())
for i in 0 to 10 {
Js.log(a[i])
}
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the CLU programming language
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Esthetic numbers step by step in the Arturo programming language
You may also check:How to resolve the algorithm Playing cards step by step in the COBOL programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Modula-2 programming language