How to resolve the algorithm Random numbers step by step in the Pascal programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Random numbers step by step in the Pascal 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 Pascal programming language

Source code in the pascal programming language

function rnorm (mean, sd: real): real;
 {Calculates Gaussian random numbers according to the Box-Müller approach}
var
  u1, u2: real;
begin
  u1 := random;
  u2 := random;
  rnorm := mean * abs(1 + sqrt(-2 * (ln(u1))) * cos(2 * pi * u2) * sd); 
       /* error !?! Shouldn't it be "mean +" instead of "mean *" ? */
end;


  

You may also check:How to resolve the algorithm Time a function step by step in the Pike programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the SNUSP programming language
You may also check:How to resolve the algorithm Terminal control/Coloured text step by step in the Julia programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the E programming language
You may also check:How to resolve the algorithm SHA-256 Merkle tree step by step in the Mathematica/Wolfram Language programming language