RandG (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example generates 1000 normally distributed random numbers about the Mean = 1.0 with standard deviation 0.5 and outputs the statistical Mean and Standard Deviation of the distribution generated.

Code

program NormalRandoms;

{$APPTYPE CONSOLE}

uses
  Math;

var
  Values: array[0..999] of Double;
  I: Integer;

begin
  Randomize;
  for I:= Low(Values) to High(Values) do
    Values[I]:= RandG(1.0, 0.5);    // Mean = 1.0, StdDev = 0.5
  Writeln('Mean          = ', Mean(Values):6:4);
  Writeln('Std Deviation = ', StdDev(Values):6:4);
  Readln;
end.

Uses

See Also