Random

Random related methods.


nzRandom()

function nzRandom(): Double;

Generates a random number that is never 0.


SRL.GaussRand

function TSRL.GaussRand(Mean, Dev: Double): Double;

Generates a random gaussian/normal number.


SRL.TruncatedGauss

function TSRL.TruncatedGauss(Left:Double=0; Right:Double=1; CUTOFF:Single=0): Double; static;
function TSRL.TruncatedGauss(Left:Int64=0; Right:Int64=1; CUTOFF:Single=0): Int64; static; overload;

Generates a random gaussian/normal number which is truncated and mapped within then given range [left..right] weighted towards left


SRL.SkewedRand

function TSRL.SkewedRand(Mode, Lo, Hi: Double; CUTOFF:Single=0): Double; static;
function TSRL.SkewedRand(Mode, Lo, Hi: Int64; CUTOFF:Single=0): Int64; static; overload;

Random skewed distribution generation. Mode is a number between Lo and Hi which is where the most of the generated numbers will land.


SRL.NormalRange

function TSRL.NormalRange(Min, Max: Double; CUTOFF:Single=0): Double; constref;
function TSRL.NormalRange(Min, Max: Int64; CUTOFF:Single=0): Int64; constref; overload;

Generates a random float or integer in the given range, weighted towards the mean.


SRL.RandomPoint

function TSRL.RandomPoint(mean: TPoint; MaxRad: Int32): TPoint;
function TSRL.RandomPoint(bounds: TBox): TPoint; overload;
function TSRL.RandomPoint(rect: TRectangle): TPoint; overload;

Generates a random TPoint which weights around Mean, with a max distance from mean defined by MaxRad. If a TBox or a TRectangle are passed, the mean point of those will be used.


SRL.RandonPointEx

function TSRL.RandonPointEx(From: TPoint; B: TBox; Force: Double=0.35): TPoint; constref;

Generates a random point within the bounds of the given box B, the point generated is skewed towards towards the From-point. The last parameter Force defines how much the generated point is to be skewed towards or away from From - Expects value in the range 0..2

  • Force = 0: Result weighs heavily towrads the edge closest to From

  • Force = 1: Result in the middle of box is most common

  • Force = 2: Result weighs heavily towrads the edge furthest away from From


SRL.ROWP

function TSRL.ROWP(From: TPoint; Rect: TRectangle; Force: Double=-0.9; Smoothness: Double=PI/12): TPoint;
function TSRL.ROWP(From: TPoint; Box: TBox; Force: Double=-0.9; Smoothness: Double=PI/12): TPoint;

ROWP, short for Random Olly Weighted Point. Generates a random point based on a rough formula that Olly came up with for weighting points towards “From” point. Final implementation and math done by slacky.

Force ranges from -1 (close to) to 1 (away from), where 0 is mean, but with a bit of a skewiness…


SRL.Dice

function TSRL.Dice(ChancePercent: Double): Boolean; static;

Generates a random number and returns True whenever the value generated is within the chance (in percentage).

Example:

if SRL.Dice(10.5) then
  WriteLn('This has a 10.5 percent chance of writing')
else
  WriteLn('No dice');

Wait

procedure Wait(Min, Max: Double; Weight: EWaitDir=wdMean); overload;

Waits … Weighted towards the mean of Min and Max


WaitEx

procedure WaitEx(Mean, Dev: Double);

Waits … Regular gauss random


TPoint.Random

function TPoint.Random(min, max: Integer; gauss: Boolean = False): TPoint; constref;
function TPoint.Random(XMin, XMax: Integer; YMin, YMax: Integer; Gauss: Boolean = False): TPoint; constref; overload;

Randomizes the current point by a min and max values.

Example

var
  p: TPoint = [100, 100];

begin
  p := p.Random(5, 20);
  WriteLn p;
end;