TRandomGenerator Class

Source: RndGenerators.cs · Assembly: Dew.Math

public class TRandomGenerator

Random generator.

Use this class to generate streams of random numbers. To achieve independence between two series of random numbers there are three options: 1. create several instances of this class and initialize each with a different seed. (and maybe a different random generator). 2. create a single instance of this class and use leapfroging. 3. create a single instance of this class and use block splitting.

Examples

csharp
TRandomGenerator rnd;
TVecInt IntVec;
if Seed = -1 then Seed = aRound(Random*High(Cardinal));

rnd = TRandomGenerator.Create;
IntVec = TVecInt.Create;
try
    {
        IntVec.Size(Results.Length, prInt32);

        rnd.StreamCount = 1;
        rnd.Init(rgMRG32k3a,Seed);
        rnd.Streamsnew double[] {0}.RandomBinomial(IntVec,an,p);
        Results.Copy(IntVec);
    }
finally
    {
        rnd.Free;
        IntVec.Free;
    end
}

Properties

NameTypeDescription
BasicRngTypeTBasicRandomGeneratorThe basic random generator used.
BlockStepInt32A parameter to the block splitting method to achieve stream independence.
ItemTRngStreamA list of independent random streams.
SeedInt32The random generator seed.
StreamCountInt32Number of independent random streams.
StreamIndependenceTRngStreamIndependenceSpecifies the method to achieve random stream independence.

Methods

NameDescription
InitInitializes random generator.
LoadFromFileLoads random generator state from File.
LoadFromStreamLoads random generator state from Src.
SaveToFileSaves random generator state to File.
SaveToStreamSaves random generator state to Dst.