function
Tests.RuleChecks.pseudoRandom
Deterministic pseudo-random stream on [-1, 1]
Public declarations
Explicit source declarations; dimensions, modifications and defaults are shown as written, without evaluation.
| Role | Name | Type | Dimensions / attributes / default | Description |
|---|---|---|---|---|
| input | seed | Integer | | Seed in 1 .. 2147483646 |
| input | count | Integer | | Number of values to draw |
| output | values | Real | [count] |
Modelica declarations and implementation
Show parameters, interfaces and source
Parameters, inputs, outputs, defaults and equations from the source file.
function pseudoRandom "Deterministic pseudo-random stream on [-1, 1]"
input Integer seed "Seed in 1 .. 2147483646";
input Integer count "Number of values to draw";
output Real values[count];
protected
Real state;
algorithm
state := seed;
for i in 1:count loop
// Park and Miller minimal standard generator. Both factors stay below
// 2^53, so the recurrence is exact in binary64 and every tool that runs
// this suite draws the identical points.
state := mod(16807.0 * state, 2147483647.0);
values[i] := 2.0 * (state / 2147483647.0) - 1.0;
end for;
end pseudoRandom;