User guide

3. MRG32K3A
4. Wichmann-Hill
5. Kiss-Monster
Beyondsimplychoosingthefastestavailablegenerators,twocodingtechniquescanalso
causeyourprogramstorunfaster.Thefirstiscreatinglargernumbersofrandomdevi-
atesatatime.Forexample,creatingonemillionrandomnumbersinonecallwillbe
muchfasterthancreatingthesameonemillionnumbersthrough100,000callsthateach
create10numbers.Creatingtoomanynumbersatoncecanalsoslowdownyourpro-
gram'sperformanceiftheresultingmatrixtakesuptoomuchofyouravailableRAM.
Thekeypointistoavoidcreatinglargerandommatricesoneortwonumbersatatime.
Thesecondcodingtechniqueisincorporatemulti-threadingintoyourrandomnumbergen-
eration.Thisiscoveredinthenextsectionofthischapter.
12.2 Thread-safe Random Number Generators
Eachsuccessivenumberinapseudo-randomsequenceiscomputedbaseduponthegen-
erator'scurrentstate.TheRNGsinGAUSSthattakeandreturnastate,suchas
rndKMuandrndGamma,areinherentlythread-safe.Thesefunctionscanbeusedinde-
pendentlyinseparatethreadsaslongasthesamestatevariableisnotwrittentoinmore
thanoneconcurrentthread.Functionsthatdonottakeorreturnastateshouldnotbe
usedinsideconcurrentthreadsets.Forexample,thefollowingisnotalegalprogram:
ThreadBegin;
x = rndn(500, 1);
y = myFunction(x);
ThreadEnd;
ThreadBegin;
x2 = rndn(500, 1);
y2 = myFunction(x2);
ThreadEnd;
ThreadJoin;
12-4
GAUSSUser Guide
Random Number
Generation