Home

SSJ User's Guide Package rng Random Number Generators

image

Contents

1. RandomStreamBase This class provides a convenient foundation on which RNGs can be built It implements all the methods which do not depend directly on the generator itself but only on its out put which is to be defined by implementing the abstract method nextValue In the present class all methods returning random numbers directly or indirectly nextDouble nextArrayOfDouble nextInt and nextArray0fInt call nextValue Thus to define a subclass that implements a RNG it suffices to implement nextValue in addition to the reset and toString methods Of course the other methods may also be overridden for improved efficiency If the nextValue already generates numbers with a precision of 53 bits or higher then nextDouble can be overridden to improve the performance The mechanism for increasing the precision assumes that nextValue returns at least 29 bits of precision in which case the higher precision numbers will have roughly 52 bits of precision This mechanism was designed primarily for RNGs that return numbers with around 30 to 32 bits of precision package umontreal iro lecuyer rng public abstract class RandomStreamBase implements RandomStream public abstract void resetStartStream public abstract void resetStartSubstream public abstract void resetNextSubstream public abstract String toString public void increasedPrecision boolean incp After calling this method with incp true each call to the RNG direct
2. LFSR258 ape 35 0 18 MT19937 J a3 36 46 GenF2w32 2999 43 556 MRG31k3p ales 51 0 89 F2NL607 3637 65 329 MRG32k3a 21 70 1 1 RandRijndael 2130 127 0 6 Other tools included in this package permit one to manage and synchronize several streams simultaneously RandomStreamManager to create random stream factories for a given type of stream BasicRandomStreamFactory and to apply automatic transforma tions to the output of a given stream AntitheticStream and BakerTransformedStream For further details about uniform RNGs we refer the reader to 1 6 7 RandomStream This interface defines the basic structures to handle multiple streams of uniform pseudo random numbers and convenient tools to move around within and across these streams The actual random number generators RNGs are provided in classes that implement this RandomStream interface Each stream of random numbers is an object of the class that implements this interface and can be viewed as a virtual random number generator For each type of base RNG i e each implementation of the RandomStream interface the full period of the generator is cut into adjacent streams or segments of length Z and each of these streams is partitioned into V substreams of length W where Z VW The values of V and W depend on the specific RNG but are usually larger than 2 Thus the distance Z between the starting points of two successive streams provided by an RNG usual
3. u int start int n Fills up the array by calling nextInt i j 16 TruncatedRandomStream Represents a container random stream generating numbers in an interval a b where a lt b and a b 0 1 by using another stream package umontreal iro lecuyer rng public class TruncatedRandomStream implements RandomStream Constructor public TruncatedRandomStream RandomStream stream double a double b 17 RandMrg This class is DEPRECATED This class implements directly the interface RandomStream with a few additional tools It uses the same backbone or main generator as in MRG32k3a but it is an older implementation that does not extend the class RandomStreamBase and it is around 10 slower package umontreal iro lecuyer rng public class RandMrg implements RandomStream Constructors public RandMrg Constructs a new stream initializes its seed Ij sets By and Cy equal to Ig and sets its antithetic switch to false The seed J is equal to the initial seed of the package given by setPackageSeed if this is the first stream created otherwise it is Z steps ahead of that of the stream most recently created in this class public RandMrg String name Constructs a new stream with an identifier name can be used when printing the stream state in error messages etc Methods public static void setPackageSeed long seed Sets the initial seed for the class RandMrg to the six integers in the vector
4. seed 0 5 This will be the seed initial state of the first stream If this method is not called the default initial seed is 12345 12345 12345 12345 12345 12345 If it is called the first 3 values of the seed must all be less than m1 4294967087 and not all 0 and the last 3 values must all be less than m2 4294944443 and not all 0 public void increasedPrecis boolean incp After calling this method with incp true each call to the generator direct or indirect for this stream will return a uniform random number with roughly 53 bits of resolution instead of 32 bits and will advance the state of the stream by 2 steps instead of 1 More precisely if s is a stream of the class RandMrg in the non antithetic case the instruc tion u s nextDouble when the resolution has been increased is equivalent to u s nextDouble s nextDouble fact 1 0 where the constant fact is equal to 2 24 This also applies when calling nextDouble indirectly e g via next Int etc By default or if this method is called again with incp false each call to nextDouble for this stream advances the state by 1 step and returns a number with 32 bits of resolution 18 RandMrg public void advanceState int e int c Advances the state of this stream by k values without modifying the states of other streams as in setSeed nor the values of By and J associated with this stream If e gt 0 then k 2 c if e lt 0
5. stream at the beginning of a stream with the initial seed seed 0 31 The seed must satisfy the same conditions as in setPackageSeed This method only affects the specified stream the others are not modified Hence after calling this method the beginning of the streams will no longer be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public int getState Returns the current state of the stream represented as an array of 32 integers 28 GenF2w32 Implements the RandomStream interface via inheritance from RandomStreamBase The back bone generator is a Linear Congruential Generator LCG in the finite field Faw instead of F gt The implemented generator is the GenF2w2_32 proposed by Panneton 15 14 Its state is 25 32 bit words and it has a period length of 28 1 The values of V W and Z are 220 2300 and 2500 respectively see RandomStream for their definition The seed of the RNG and the state of a stream at any given step is a 25 dimensional vector of 32 bits integers Its nextValue method returns numbers with 32 bits of precision package umontreal iro lecuyer rng public class GenF2w32 extends RandomStreamBase Constructors public GenF2w32 Constructs a new stream public GenF2w32 String name Constructs a new stream with the identifier name used in the
6. toString method Methods public static void setPackageSeed int seed Sets the initial seed of the class GenF2w2r32 to the 25 integers of the vector seed 0 24 This will be the initial seed of the class for the next created stream At least one of the integers must be non zero public void setSeed int seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial seed seed 0 24 The seed must satisfy the same conditions as in setPackageSeed This method only affects the specified stream the others are not modified Hence after calling this method the beginning of the streams will no longer be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public int getState Returns the current state of the stream represented as an array of 25 integers 29 MT19937 Implements the RandomStream interface via inheritance from RandomStreamBase The back bone generator is the MT19937 Mersenne Twister proposed by Matsumoto and Nishimura 13 which has a state size of 19937 bits and a period length of p amp 2 7 Each instance uses another RandomStream to fill its initial state With this design the initial states of successive streams are not spaced by an equal number of steps and there is no guarantee that different streams do not overlap but damagi
7. u instead of u and the corresponding change is made in nextInt Any instance of this class behaves exactly like a RandomStream except that it depends on another random number generator stream called the base stream to generate its numbers Any call to one of the next methods of this class will modify the state of the base stream package umontreal iro lecuyer rng public class AntitheticStream implements RandomStream Constructors public AntitheticStream RandomStream stream Constructs a new antithetic stream using the random numbers from the base stream stream Methods public String toString Returns a string starting with Antithetic of and finishing with the result of the call to the toString method of the generator public double nextDouble Returns 1 0 s nextDouble where s is the base stream public int nextInt int i int j Returns j i s nextInt i j where s is the base stream public void nextArrayOfDouble double u int start int n Calls nextArrayOfDouble u start n for the base stream then replaces each uli by 1 0 uli public void nextArrayOfInt int i int j int u int start int n Calls nextArrayOfInt i j u start n for the base stream then replaces each u i by j i wbx 15 BakerTransformedStream This container class permits one to apply the baker s transformation to the output of any RandomStream It transforms each u 0 1 into 2u if u lt 1 2 a
8. umontreal iro lecuyer rng public class RandomStreamInstantiationException extends RuntimeException public RandomStreamInstantiationException RandomStreamFactory factory Constructs a new random stream instantiation exception with no message no cause and thrown by the given factory public RandomStreamInstantiationException RandomStreamFactory factory String message Constructs a new random stream instantiation exception with the given message no cause and concerning factory public RandomStreamInstantiationException RandomStreamFactory factory Throwable cause Constructs a new random stream instantiation exception with no message the given cause and concerning factory public RandomStreamInstantiationException RandomStreamFactory factory String message Throwable roi Constructs a new random stream instantiation exception with the given message the sup plied cause and concerning factory public RandomStreamFactory getRandomStreamFactory Returns the random stream factory concerned by this exception public String toString Returns a short description of the exception If getRandomStreamFactory returns null this calls super toString Otherwise the result is the concatenation of a the name of the actual class of the exception b the string For random stream factory c the result of getRandomStreamFactory toString d if getMessage is non null followed by the result of getMessage 10
9. 8 Extends RandomStreamBase using a 64 bit composite linear feedback shift register LFSR or Tausworthe RNG as defined in 3 17 This generator is the LFSR258 proposed in 5 It has five components combined by a bitwise xor Its period length is p amp 2 The values of V W and Z are 21 21 and 22 respectively see RandomStream for their definition The seed of the RNG and the state of a stream at any given step are five dimensional vectors of 32 bit integers The default initial seed of the RNG is 1234567890 1234567890 1234567890 1234567890 1234567890 The nextValue method re turns numbers with 53 bits of precision This generator is fast for 64 bit machines package umontreal iro lecuyer rng public class LFSR258 extends RandomStreamBase Constructors public LFSR258 Constructs a new stream public LFSR258 String name Constructs a new stream with the identifier name Methods public static void setPackageSeed long seed Sets the initial seed for the class LFSR258 to the five integers of array seed 0 4 This will be the initial state or seed of the next created stream The default seed for the first stream is 1234567890 1234567890 1234567890 1234567890 1234567890 The first second third fourth and fifth integers of seed must be either negative or greater than or equal to 2 512 4096 131072 and 8388608 respectively public void setSeed long seed This method is discouraged for norm
10. A stream can generate uniform variates real numbers over the interval 0 1 uniform integers over a given range of values 7 7 and arrays of these The generators provided here have various speeds and period lengths MRG32k3a is the one that has been most extensively tested but it is not among the fastest The LFSR113 GenF2w32 MT19937 and the WELL generators produce sequences of bits that obey a linear recurrence so they eventually fail statistical tests that measure the linear complexity of these bits sequences But this can affect only very special types of applications For each generator the following tables give the approximate period length period the CPU time in seconds to generate 10 U 0 1 random numbers gen time and the CPU time to jump ahead 10 times to the next substream jump time The following timings are on a 2100 MHz 32 bit AMD Athlon XP 2800 computer running Linux with the JDK 1 4 2 RNG period gen time jump time LFSR113 2113 51 0 08 WELL512 qe 55 372 WELL1024 91024 55 1450 MT19937 2 992 56 60 WELL607 2007 61 523 GenF2w32 3800 62 937 MRG31k3p 9185 66 1 8 MRG32k3a 2191 109 2 3 F2NL607 2687 125 523 RandRijndael 2130 260 0 9 The following timings are on a 2400 MHz 64 bit AMD Athlon 64 Processor 4000 com puter running Linux with the JDK 1 5 0 CONTENTS 3 RNG period gen time jump time LFSR113 oie 31 0 08 WELL607 Jor 33 329 WELL512 2 33 234 WELL1024 21024 34 917
11. SSJ User s Guide Package rng Random Number Generators Version September 17 2007 CONTENTS 1 Contents crea laa edad ad Aa a A Age ad A a pe BasicRandomStreamFactoryl o ee A de Laia a AR aa A e Eae 10 A a od o HOLA ra Bed os 12 Se ase AR ot Si O A ETE ee ee ee 14 ya ee a Gee a ae A ae Ro 15 Cy ere oh are a ae eee eee 16 A eee eee 17 NE sa tiocth a dehed Juda chiens deena a ba we dee oe 19 pasarse ab ab aia 21 A A ee eee aes 23 Tel ct Ae on hoe et Ace oe Sen Code Come ed nee ae 24 a oa a oo oho Sika ated at See ee aha a 25 a 4 o2 4 oh Cn ber dee ead etat 26 ah ed oe eee ee ee eee ee 7 a a ee Na 28 a oe ey oe 29 a 624226642 a 30 anal a o cy a ene See Gey ate Ghee ae ote eee a wee Be eS ot 33 o NI DD A N 2 CONTENTS Overview This package offers the basic facilities for generating uniform random numbers It provides an interface called RandomStream and some implementations of that interface The interface specifies that each stream of random numbers is partitioned into multiple substreams and that methods are available to jump between the substreams as discussed in 9 8 11 For an example of how to use these streams properly see InventoryCRN in the set of example programs Each implementation uses a specific backbone uniform random number generator RNG whose period length is typically partitioned into very long non overlapping segments to provide the streams and substreams
12. aining all the random streams in this random stream manager The returned list constructed by unmodifiableList can be assumed to contain non null RandomStream instances public void resetStartStream Forwards to the resetStartStream methods of all streams in the list public void resetStartSubstream Forwards to the resetStartSubstream methods of all streams in the list public void resetNextSubstream Forwards to the resetNextSubstream methods of all streams in the list RandomStreamFactory Represents a random stream factory capable of constructing instances of a given type of random stream by invoking the newInstance method each time a new random stream is needed instead of invoking directly the specific constructor of the desired type Hence if several random streams of a given type class must be constructed at different places in a large simulation program and if we decide to change the type of stream in the future there is no need to change the code at those different places With the random stream factory the class specific code for constructing these streams appears at a single place where the factory is constructed The class BasicRandomStreamFactory provides an implementation of this interface package umontreal iro lecuyer rng public interface RandomStreamFactory public RandomStream newInstance Constructs and returns a new random stream If the instantiation of the random stream fails this method th
13. al use Initializes the stream at the beginning of a stream with the initial seed seed 0 4 The seed must satisfy the same conditions as in setPackageSeed This method only affects the specified stream the others are not modified so the beginning of the streams will not be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public long getState Returns the current state of the stream represented as an array of five integers 25 WELL512 This class implements the RandomStream interface via inheritance from RandomStreamBase The backbone generator is a Well Equidistributed Long period Linear Random Number Generator WELL proposed by F Panneton in 16 14 and which has a state size of 512 bits and a period length of p 2 The values of V W and Z are 2150 2200 and 2350 respectively see RandomStream for their definition The seed of the RNG and the state of a stream at any given step is a 16 dimensional vector of 32 bit integers This implementation requires about 70K of memory to run This memory is shared between all instances of the class and is only loaded when the first instance is created package umontreal iro lecuyer rng public class WELL512 extends RandomStreamBase Constructors public WELL512 Constructs a new stream public WELL512 String name Constructs a new str
14. andomStream Constructors public RandomStreamWithCache RandomStream stream Constructs a new cached random stream with internal stream stream public RandomStreamWithCache RandomStream stream int initialCapacity Constructs a new cached random stream with internal stream stream The initialCapacity parameter is used to set the initial capacity of the internal array which can grow as needed it does not limit the total size of the cache Methods public boolean isCaching Determines if the random stream is caching values default being true When caching is turned OFF the nextDouble method simply calls the corresponding method on the internal random stream without storing the generated uniforms public void setCaching boolean caching Sets the caching indicator to caching If caching is turned OFF this method calls clearCache to clear the cached values public RandomStream getCachedStream Returns a reference to the random stream whose values are cached public void setCachedStream RandomStream stream Sets the random stream whose values are cached to stream If the stream is changed the clearCache method is called to clear the cache RandomStreamWithCache 13 public void clearCache Clears the cached values for this random stream Any subsequent call will then obtain new values from the internal stream public void initCache Resets this random stream to recover values from the cache Subsequent calls to nex
15. bined generator has a period length of p 2 The values of V W and Z are 2250 2150 and 2400 respectively see RandomStream for their definition The seed of the RNG has two part the linear part is a 19 dimensional vector of 32 bit integers while the nonlinear part is made up of a n dimensional vector of indices representing the position of the generator in each array of the nonlinear components package umontreal iro lecuyer rng public class F2NL607 Constructors public F2NL607 Constructs a new stream initializing it at its beginning Also makes sure that the seed of the next constructed stream is Z steps away Sets its antithetic switch to false and sets the stream to normal precision mode offers 32 bits of precision public F2NL607 String name Constructs a new stream with the identifier name used in the toString method Methods public static void setPackageLinearSeed int seed Sets the initial seed of the linear part of the class F2NL607 to the 19 integers of the vector seed 0 18 This will be the initial seed or seed of the next created stream At least one of the integers must be non zero and if this integer is the last one it must not be equal to Ox7FFFFFFF public void setLinearSeed int seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial linear seed seed 0 18 The seed must satisfy the same conditions F2NL607 31 as in setPac
16. c int getState Returns the current state of the stream represented as an array of 19 integers 27 WELL1024 Implements the RandomStream interface via inheritance from RandomStreamBase The back bone generator is a Well Equidistributed Long period Linear Random Number Generator WELL proposed by F Panneton in 14 and which has a state size of 1024 bits and a period length of p 21 The values of V W and Z are 2300 2400 and 2 respectively see RandomStream for their definition The seed of the RNG and the state of a stream at any given step is a 16 dimensional vector of 32 bit integers The output of nextValue has 32 bits of precision This implementation requires the use of about 250K of memory to run This memory is shared between all instances of the class and is only loaded when the first instance is created package umontreal iro lecuyer rng public class WELL1024 extends RandomStreamBase Constructors public WELL1024 Constructs a new stream public WELL1024 String name Constructs a new stream with the identifier name used in the toString method Methods public static void setPackageSeed int seed Sets the initial seed of the class WELL1024 to the 32 integers of the vector seed 0 31 This will be the initial seed of the class of the next created stream At least one of the integers must be non zero public void setSeed int seed This method is discouraged for normal use Initializes the
17. ce after calling this method the beginning of the streams will no longer be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public int getNonLinearState Returns the current state of the non linear part of the stream represented as an array of n integers where n is the number of components in the non linear generator public static int getNonLinearData Return the data of all the components of the non linear part of the random number generator This data is explained in the introduction public static void setNonLinearData int data Selects new data for the components of the non linear generator The number of arrays in data will decide the number of components Each of the arrays will be assigned to one of the components The period of the resulting non linear generator will be equal to the lowest common multiple of the lengths of the arrays It is thus recommended to choose only prime length for the best results NOTE This method cannot be called if at least one instance of F2NL607 has been con structed In that case it will throw an IllegalStateException public static void setScrambleData RandomStream rand int steps int size Selects new data for the components of the non linear generator The number of arrays in data will decide the number of components Each of the arrays will be assign
18. eam with the identifier name used in the toString method Methods public static void setPackageSeed int seed Sets the initial seed of the class WELL512 to the 16 integers of the vector seed 0 15 This will be the initial seed of the class of the next created stream At least one of the integers must be non zero public void setSeed int seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial seed seed 0 15 The seed must satisfy the same conditions as in setPackageSeed This method only affects the specified stream the others are not modified Hence after calling this method the beginning of the streams will no longer be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public int getState Returns the current state of the stream represented as an array of 16 integers 26 WELL607 This class implements the RandomStream interface via inheritance from RandomStreamBase The backbone generator is a Well Equidistributed Long period Linear Random Number Generator WELL proposed by F Panneton in HA The implemented generator is the WELL607 which has a state size of 607 bits and a period length of p 2 The values of V W and Z are 21 225 and 2400 respectively see RandomStream for their definition The seed of the RNG and
19. ectors of 32 bit integers The default initial seed of the RNG is 12345 12345 12345 12345 The nextValue method returns numbers with 32 bits of precision package umontreal iro lecuyer rng public class LFSR113 extends RandomStreamBase Constructors public LFSR113 Constructs a new stream public LFSR113 String name Constructs a new stream with the identifier name Methods public static void setPackageSeed int seed Sets the initial seed for the class LFSR113 to the four integers of the vector seed 0 3 This will be the initial state or seed of the next created stream The default seed for the first stream is 12345 12345 12345 12345 The first second third and fourth integers of seed must be either negative or greater than or equal to 2 8 16 and 128 respectively public void setSeed int seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial seed seed 0 3 The seed must satisfy the same conditions as in setPackageSeed This method only affects the specified stream the others are not modified so the beginning of the streams will not be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public int getState Returns the current state of the stream represented as an array of four integers 24 LFSR25
20. ed to one of 32 F2NL607 the components The period of the resulting non linear generator will be equal to the lowest common multiple of the lengths of the arrays It is thus recommended to choose only prime length for the best results NOTE This method cannot be called if at least one instance of F2NL607 has been con structed In that case it will throw an IllegalStateException 33 RandRijndael Implements a RNG using the Rijndael block cipher algorithm AES with key and block lengths of 128 bits A block of 128 bits is encrypted by the Rijndael algorithm to generate 128 pseudo random bits Those bits are split into four words of 32 bits which are returned successively by the method nextValue The unencrypted block is the state of the generator It is incremented by 1 at every four calls to nextValue Thus the period is 21 and jumping ahead is easy The values of V W and Z are 2 22 and 2 respectively see RandomStream for their definition Seeds states must be given as 16 dimensional vectors of bytes 8 bit integers The default initial seed is a vector filled with zeros The Rijndael implementation used here is that of the Cryptix Development Team which can be found on the Rijndael creators page http www esat kuleuven ac be rijmen rijndael package umontreal iro lecuyer rng public class RandRijndael extends RandomStreamBase Constructors public RandRijndael Constructs a new stream public RandRij
21. er from the discrete uniform distribution over the integers i i 1 7 using this stream Calls nextDouble once public void nextArrayOfInt int i int j int u int start int n Generates n pseudo random numbers from the discrete uniform distribution over the inte gers 1 1 1 7 using this stream and stores the result in the array u starting at index start Calls nextInt n times RandomStream Manager Manages a list of random streams for more convenient synchronization All streams in the list can be reset simultaneously by a single call to the appropriate method of this stream manager instead of calling explicitly the reset method for each individual stream After a random stream manager is constructed any existing RandomStream object can be registered to this stream manager i e added to the list and eventually unregistered removed from the list package umontreal iro lecuyer rng public class RandomStreamManager public RandomStream add RandomStream stream Adds the given stream to the internal list of this random stream manager and returns the added stream public boolean remove RandomStream stream Removes the given stream from the internal list of this random stream manager Returns true if the stream was properly removed false otherwise public void clear Removes all the streams from the internal list of this random stream manager public List getStreams Returns an unmodifiable list cont
22. ive generators with mul tipliers of the form a 21 2 In J A Joines R R Barton K Kang and P A Fishwick editors Proceedings of the 2000 Winter Simulation Conference pages 683 689 Pistacaway NJ 2000 IEEE Press M Matsumoto and T Nishimura Mersenne twister A 623 dimensionally equidis tributed uniform pseudo random number generator ACM Transactions on Modeling and Computer Simulation 8 1 3 30 1998 14 REFERENCES 35 F Panneton Construction d ensembles de points bas e sur des r currences lin aires dans un corps fini de caract ristique 2 pour la simulation Monte Carlo et l int gration quasi Monte Carlo PhD thesis D partement d informatique et de recherche op rationnelle Universit de Montr al Canada August 2004 F Panneton and P L Ecuyer Random number generators based on linear recurrences in Fow In H Niederreiter editor Monte Carlo and Quasi Monte Carlo Methods 2002 pages 367 378 Berlin 2004 Springer Verlag F Panneton P L Ecuyer and M Matsumoto Improved long period generators based on linear recurrences modulo 2 ACM Transactions on Mathematical Software 32 1 1 16 2006 S Tezuka and P L Ecuyer Efficient and portable combined Tausworthe random number generators ACM Transactions on Modeling and Computer Simulation 1 2 99 112 1991
23. kageSeed The non linear seed is not modified thus the non linear part of the random number generator is reset to the beginning of the old stream This method only affects the specified stream the others are not modified Hence after calling this method the beginning of the streams will no longer be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public int getLinearState Returns the current state of the linear part of the stream represented as an array of 19 integers public static void setPackageNonLinearSeed int seed Sets the non linear part of the initial seed of the class F2NL607 to the n integers of the vector seed 0 n 1 where n is the number of components of the non linear part The default is n 3 Each of the integers must be between 0 and the length of the corresponding component minus one By default the lengths are 1019 1021 1031 public void setNonLinearSeed int seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial non linear seed seed 0 n 1 where n is the number of components of the non linear part of the generator The linear seed is not modified so the linear part of the random number generator is reset to the beginning of the old stream This method only affects the specified stream the others are not modified Hen
24. l state of the first stream If this method is not called the default initial seed is 12345 12345 12345 12345 12345 12345 If it is called the first 3 values of the seed must all be less than m1 4294967087 and not all 0 and the last 3 values must all be less than m2 4294944443 and not all 0 public void setSeed long seed Sets the initial seed I of this stream to the vector seed 0 5 This vector must satisfy the same conditions as in setPackageSeed The stream is then reset to this initial seed The states and seeds of the other streams are not modified As a result after calling this method the initial seeds of the streams are no longer spaced Z values apart For this reason this method should be used only in very exceptional situations I have never used it myself proper use of reset and of the stream constructor is preferable public long getState Returns the current state Cy of this stream This is a vector of 6 integers This method is convenient if we want to save the state for subsequent use 20 MRG32k3a public String toString Returns a string containing the name and the current state Cy of this stream public String toStringFull Returns a string containing the name of this stream and the values of all its internal variables 21 MRG31k3p Extends the abstract class RandomStreamBase thus implementing the RandomStream in terface indirectly The backbone generator is the combined multip
25. le recursive generator CMRG MRG31k3p proposed by L Ecuyer and Touzin 12 implemented in 32 bit integer arithmetic This RNG has a period length of p 21 The values of V W and Z are 2 27 and 2 respectively See RandomStream for their definition The seed and the state of a stream at any given step are six dimensional vectors of 32 bit integers The default initial seed is 12345 12345 12345 12345 12345 12345 The method nextValue provides 31 bits of precision The difference between the RNG of class MRG32k3a and this one is that this one has all its coefficients of the form a 2 2 This permits a faster implementation than for arbitrary coefficients On a 32 bit computer MRG31k3p is about twice as fast as MRG32k3a On the other hand the latter does a little better in the spectral test and has been more extensively tested package umontreal iro lecuyer rng public class MRG31k3p extends RandomStreamBase Constructors public MRG31k3p Constructs a new stream initialized at its beginning Its seed is Z the previous seed 21 steps away from public MRG31k3p String name Constructs a new stream with the identifier name used when formatting the stream state Methods public static void setPackageSeed int seed Sets the initial seed for the class MRG31k3p to the six integers of the vector seed 0 5 This will be the initial state or seed of the next created stream By default if this method i
26. ling increasedPrecis for this stream the resolution is higher and the stream state advances by two steps 19 MRG32k3a Extends the abstract class RandomStreamBase by using as a backbone or main generator the combined multiple recursive generator CMRG MRG32k3a proposed by L Ecuyer 4 im plemented in 64 bit floating point arithmetic This backbone generator has a period length of p 21 The values of V W and Z are 2 26 and 2 respectively See RandomStream for their definition The seed of the RNG and the state of a stream at any given step are six dimensional vectors of 32 bit integers stored in double The default initial seed of the RNG is 12345 12345 12345 12345 12345 12345 package umontreal iro lecuyer rng public class MRG32k3a extends RandomStreamBase Constructors public MRG32k3a Constructs a new stream initializes its seed I sets B and Cy equal to J and sets its antithetic switch to false The seed 1 is equal to the initial seed of the package given by setPackageSeed if this is the first stream created otherwise it is Z steps ahead of that of the stream most recently created in this class public MRG32k3a String name Constructs a new stream with an identifier name used when printing the stream state Methods public static void setPackageSeed long seed Sets the initial seed for the class MRG32k3a to the six integers in the vector seed 0 5 This will be the seed initia
27. ly exceeds 21 The initial seed of the RNG is the starting point of the first stream It has a default value for each type of RNG but this initial value can be changed by calling setPackageSeed for the corresponding class Each time a new RandomStream is created its starting point initial seed is computed automatically Z steps ahead of the starting point of the previously created stream of the same type and its current state is set equal to this starting point For each stream one can advance by one step and generate one value or go ahead to the beginning of the next substream within this stream or go back to the beginning of the current substream or to the beginning of the stream or jump ahead or back by an arbitrary number of steps Denote by Cy the current state of a stream g J its initial state B the state at the beginning of the current substream and N the state at the beginning of the next substream The following diagram shows an example of a stream whose state is at the 6th value of the third substream i e 2W 5 steps ahead of its initial state J and 5 steps ahead of its state B The form of the state of a stream depends on its type For example the state of a stream of class MRG32k3a is a vector of six 32 bit integers represented internally as floating point numbers in double Cy PA NA ES Tp UTA AA T I Bg Ny The methods for manipulating the streams and generating random numbers are imple mented differe
28. method always uses the highest order bits of the random number It should be overridden if a faster implementation exists for the specific generator public void nextArrayOfInt int i int j int u int start int n Calls nextInt n times to fill the array u This method should be overridden if a faster implementation exists for the specific generator public String formatState Deprecated use the toString method 12 RandomStreamWithCache This class represents a random stream whose uniforms are cached for more efficiency when using common random numbers An object from this class is constructed with a reference to a RandomStream instance used to get the random numbers These numbers are stored in an internal array to be retrieved later The dimension of the array increases as the values are generated If the nextDouble method is called after the object is reset it gives back the cached values instead of computing new ones If the cache is exhausted before the stream is reset new values are computed and added to the cache Such caching allows for a better performance with common random numbers when gen erating uniforms is time consuming It can also help with restoring the simulation to a certain state without setting stream specific seeds However using such caching may lead to memory problems if a large quantity of random numbers are needed package umontreal iro lecuyer rng public class RandomStreamWithCache implements R
29. nd 2 1 u if u gt 1 2 The nextDouble method will return the result of this transformation and the other next methods are affected accordingly Any instance of this class contains a RandomStream called its base stream used to generate its numbers and to which the transformation is applied Any call to one of the next methods of this class will modify the state of the base stream The baker transformation is often applied when the RandomStream is actually an iterator over a point set used for quasi Monte Carlo integration see the hups package package umontreal iro lecuyer rng public class BakerTransformedStream implements RandomStream Constructors public BakerTransformedStream RandomStream stream Constructs a new baker transformed stream using the random numbers from the base stream stream Methods public String toString Returns a string starting with Baker transformation of and finishing with the result of the call to the toString method of the generator public double nextDouble Returns the baker transformation of s nextDouble where s is the base stream public int nextInt int i int j Generates a random integer in j via nextDouble in which the baker transformation is applied public void nextArrayOfDouble double u int start int n Calls nextArrayOfDouble u start n for the base stream then applies the baker trans formation public void nextArrayOfInt int i int j int
30. ndael String name Constructs a new stream with the identifier name used in the toString method Methods public static void setPackageSeed byte seed Sets the initial seed for the class RandRijndael to the 16 bytes of the vector seed 0 15 This will be the initial state or seed of the next created stream The default seed for the first stream is 0 0 0 0 public void setSeed byte seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial seed seed 0 15 This method only affects the specified stream the others are not modified so the beginning of the streams will not be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable public byte getState Returns the current state of the stream represented as an array of four integers It should be noted that each state of this generator returns 4 successive values The particular value of these 4 which will be returned next is not given by this method 34 REFERENCES References 10 11 12 13 D E Knuth The Art of Computer Programming Volume 2 Seminumerical Algo rithms Addison Wesley Reading MA third edition 1998 A M Law and W D Kelton Simulation Modeling and Analysis McGraw Hill New York NY third edition 2000 P L Ecuyer Maximally e
31. ng overlap is unlikely because of the huge size of the state space The seed of the RNG and the state of a stream at any given step is a 624 dimensional vector of 32 bit integers The output of nextValue has 32 bits of precision package umontreal iro lecuyer rng public class MT19937 extends RandomStreamBase Constructors public MT19937 RandomStream rng Constructs a new stream using rng to fill its initial state public MT19937 RandomStream rng String name Constructs a new stream with the identifier name used in the toString method 30 F2NL607 Implements the RandomStream interface by using as a backbone generator the combination of the WELL607 proposed in 14 16 and implemented in WELL607 with a nonlinear generator This nonlinear generator is made up of a small number of components say n combined via addition modulo 1 Each component contains an array already filled with a random permutation of 0 s 1 where s is the size of the array These numbers and the lengths of the components can be changed by the user Each call to the generator uses the next number in each array or the first one if we are at the end of the array By default there are 3 components of lengths 1019 1021 and 1031 respectively The non linear generator is combined with the WELL using a bitwise XOR operation This ensures that the new generator has at least as much equidistribution as the WELL607 as shown in IO The com
32. ntly for each type of RNG The methods whose formal parameter types do not depend on the RNG type are specified in the interface RandomStream The others e g for setting the seeds are given only in the classes that implement the specific RNG types See 2 9 11 for examples of situations where the multiple streams offered here are useful Methods for generating random variates from non uniform distributions are provided in the randvar package RandomStream 5 package umontreal iro lecuyer rng public interface RandomStream Methods public void resetStartStream Reinitializes the stream to its initial state Ij Cy and B are set to Ig public void resetStartSubstream Reinitializes the stream to the beginning of its current substream Cy is set to By public void resetNextSubstream Reinitializes the stream to the beginning of its next substream Ny is computed and C4 and B are set to Ny public String toString Returns a string containing the current state of this stream public double nextDouble Returns a pseudo random number from the uniform distribution over the interval 0 1 using this stream after advancing its state by one step public void nextArrayOfDouble double u int start int n Generates n pseudo random numbers from the uniform distribution and stores them into the array u starting at index start public int nextInt int i int j Returns a pseudo random numb
33. or indirect for this stream will return a uniform random number with more bits of precision than what is returned by nextValue and will advance the state of the stream by 2 steps instead of 1 i e nextValue will be called twice for each random number More precisely if s is a stream of a subclass of RandomStreamBase when the preci sion has been increased the instruction u s nextDouble is equivalent to u s nextValue s nextValue fact 1 0 where the constant fact is equal to 2724 This also applies when calling nextDouble indirectly e g via nextInt etc By default or if this method is called again with incp false each call to nextDouble for this stream advances the state by 1 step and returns the same number as nextValue protected abstract double nextValue This method should return the next random number between 0 and 1 from the current stream If the stream is set to the high precision mode increasedPrecision true was called then each call to nextDouble will call nextValue twice otherwise it will call it only once public double nextDouble Returns a random number between 0 and 1 from the stream Its behavior depends on the last call to increasedPrecision RandomStreamBase 11 public void nextArrayOfDouble double u int start int n Calls nextDouble n times to fill the array u public int nextInt int i int j Calls nextDouble once to create one integer between i and j This
34. quidistributed combined Tausworthe generators Mathematics of Computation 65 213 203 213 1996 P L Ecuyer Good parameters and implementations for combined multiple recursive random number generators Operations Research 47 1 159 164 1999 P L Ecuyer Tables of maximally equidistributed combined LFSR generators Mathe matics of Computation 68 225 261 269 1999 P L Ecuyer Software for uniform random number generation Distinguishing the good and the bad In Proceedings of the 2001 Winter Simulation Conference pages 95 105 Pistacaway NJ 2001 IEEE Press P L Ecuyer Random number generation In J E Gentle W Haerdle and Y Mori editors Handbook of Computational Statistics pages 35 70 Springer Verlag Berlin 2004 Chapter II 2 P L Ecuyer and T H Andres A random number generator based on the combination of four LCGs Mathematics and Computers in Simulation 44 99 107 1997 P L Ecuyer and S Cot Implementing a random number package with splitting facilities ACM Transactions on Mathematical Software 17 1 98 111 1991 P L Ecuyer and J Granger Pich Combined generators with components from different families Mathematics and Computers in Simulation 62 395 404 2003 P L Ecuyer R Simard E J Chen and W D Kelton An object oriented random number package with many long streams and substreams Operations Research 50 6 1073 1075 2002 P L Ecuyer and R Touzin Fast combined multiple recurs
35. rows a RandomStreamInstantiationException BasicRandomStreamFactory Represents a basic random stream factory that can constructs new instances of a given RandomStream implementation via the newInstance method The class name of the imple mentation to be used must be passed to the constructor as a String which must be the name of a nullary constructor of a RandomStream object i e a constructor that has no parameters The streams are constructed by the factory by reflection from this String package umontreal iro lecuyer rng public class BasicRandomStreamFactory implements RandomStreamFactory public BasicRandomStreamFactory Class rsClass Constructs a new basic random stream factory with random stream class rsClass The supplied class object must represent an implementation of RandomStream and must provide a nullary constructor For example to construct a factory producing MRG32k3a random streams this constructor must be called with MRG33k3a class public Class getRandomStreamClass Returns the random stream class associated with this object public void setRandomStreamClass Class rsClass Sets the associated random stream class to rsClass The supplied class object must repre sent an implementation of RandomStream and must provide a nullary constructor RandomStreamInstantiationException This exception is thrown when a random stream factory cannot instantiate a stream on a call to its newInstance method package
36. s not called the first stream is created with the seed 12345 12345 12345 12345 12345 12345 If it is called the first 3 values of the seed must all be less than m 2147483647 and not all 0 and the last 3 values must all be less than m2 2147462579 and not all 0 public void setSeed int seed Use of this method is strongly discouraged Initializes the stream at the beginning of a stream with the initial seed seed 0 5 This vector must satisfy the same conditions as in setPackageSeed This method only affects the specified stream all the others are not modified so the beginning of the streams are no longer spaced Z values apart For 22 MRG31k3p this reason this method should be used only in very exceptional situations proper use of reset and of the stream constructor is preferable public int getState Returns the current state Cy of this stream This is a vector of 6 integers represented This method is convenient if we want to save the state for subsequent use 23 LFSR113 Extends RandomStreamBase using a composite linear feedback shift register LFSR or Tausworthe RNG as defined in 3 7 This generator is the LFSR113 proposed by 5 It has four 32 bit components combined by a bitwise xor Its period length is p 21 The values of V W and Z are 2 2 and 2 respectively see RandomStream for their definition The seed of the RNG and the state of a stream at any given step are four dimensional v
37. tDouble will return the cached uniforms until all the values are returned When the array of cached values is exhausted the internal random stream is used to generate new values which are added to the internal array as well This method is equivalent to calling setCacheIndex public int getNumCachedValues Returns the total number of values cached by this random stream public int getCacheIndex Return the index of the next cached value that will be returned by the stream If the cache is exhausted the returned value corresponds to the value returned by getNumCachedValues and a subsequent call to nextDouble will generate a new variate rather than reading a previous one from the cache If caching is disabled this always returns 0 public void setCacheIndex int newIndex Sets the index in the cache of the next value returned by nextDouble If newIndex is 0 this is equivalent to calling initCache If newIndex is getNumCachedValues subsequent calls to nextDouble will add new values to the cache public DoubleArrayList getCachedValues Returns an array list containing the values cached by this random stream public void setCachedValues DoubleArrayList values Sets the array list containing the cached values to values This resets the cache index to the size of the given array 14 AntitheticStream This container class allows the user to force any RandomStream to return antithetic variates That is nextDouble returns 1
38. the state of a stream at any given step is a 19 dimensional vector of 32 bit integers The output of nextValue has 32 bits of precision This implementation requires the use of about 100K of memory to run This memory is shared between all instances of the class and is only loaded when the first instance is created package umontreal iro lecuyer rng public class WELL607 extends WELL607base Constructors public WELL607 Constructs a new stream public WELL607 String name Constructs a new stream with the identifier name used in the toString method Methods public static void setPackageSeed int seed Sets the initial seed of the class WELL607 to the 19 integers of the vector seed 0 18 This will be the initial seed of the next created stream At least one of the integers must not be zero and if this integer is the last one it must not be equal to 0x80000000 public void setSeed int seed This method is discouraged for normal use Initializes the stream at the beginning of a stream with the initial seed seed 0 18 The seed must satisfy the same conditions as in setPackageSeed This method only affects the specified stream the others are not modified Hence after calling this method the beginning of the streams will no longer be spaced Z values apart For this reason this method should only be used in very exceptional cases proper use of the reset methods and of the stream constructor is preferable publi
39. then k 2 c and if e 0 then k c Note cis allowed to take negative values This method should be used only in very exceptional cases proper use of the reset methods and of the stream constructor cover most reasonable situations public void setSeed long seed Sets the initial seed J of this stream to the vector seed 0 5 This vector must satisfy the same conditions as in setPackageSeed The stream is then reset to this initial seed The states and seeds of the other streams are not modified As a result after calling this method the initial seeds of the streams are no longer spaced Z values apart For this reason this method should be used only in very exceptional situations proper use of reset and of the stream constructor is preferable public double getState Returns the current state Cy of this stream This is a vector of 6 integers represented in floating point format This method is convenient if we want to save the state for subsequent use public String toStringFull Returns a string containing the name of this stream and the values of all its internal variables public double nextDouble Returns a pseudo random number from the uniform distribution over the interval 0 1 using this stream after advancing its state by one step Normally the returned number has 32 bits of resolution in the sense that it is always a multiple of 1 2 208 However if the precision has been increased by cal

Download Pdf Manuals

image

Related Search

Related Contents

Minka Lavery 4750-206 Installation Guide  ASUS Transformer Pad TF300T 32GB Blue    USER MANUAL PUBLISHER  Le partage des plannings inter  Cargador espía de pared Yatek Manual de usuario  Elastix Call Center Manual  Mode d`emploi 522 621  SR137 Manuale Tecnico  vc50hd - manual  

Copyright © All rights reserved.
Failed to retrieve file