How to resolve the algorithm Random numbers step by step in the Sather programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Random numbers step by step in the Sather 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 Sather programming language
Source code in the sather programming language
class MAIN is
main is
a:ARRAY{FLTD} := #(1000);
i:INT;
RND::seed(2010);
loop i := 1.upto!(1000) - 1;
a[i] := 1.0d + 0.5d * RND::standard_normal;
end;
-- testing the distribution
mean ::= a.reduce(bind(_.plus(_))) / a.size.fltd;
#OUT + "mean " + mean + "\n";
a.map(bind(_.minus(mean)));
a.map(bind(_.pow(2.0d)));
dev ::= (a.reduce(bind(_.plus(_))) / a.size.fltd).sqrt;
#OUT + "dev " + dev + "\n";
end;
end;
You may also check:How to resolve the algorithm Deepcopy step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm CSV data manipulation step by step in the OCaml programming language
You may also check:How to resolve the algorithm GUI/Maximum window dimensions step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Top rank per group step by step in the TXR programming language