Package org.eclipse.epsilon.emg.random
Class EmgRandomGenerator
- java.lang.Object
-
- org.eclipse.epsilon.emg.random.EmgRandomGenerator
-
- All Implemented Interfaces:
org.apache.commons.math3.random.RandomGenerator,IEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
public class EmgRandomGenerator extends java.lang.Object implements IEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
The simplest implementation of the RandomAttributeGenerator interface. All attributes are generated as strings. It is the responsibility of the calling class/method to do the appropriate conversion. This classes uses the Apache Commons Math RandomDataGenerator.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.epsilon.emg.random.IEmgRandomGenerator
IEmgRandomGenerator.DefaultCharacterSet, IEmgRandomGenerator.Distribution
-
-
Constructor Summary
Constructors Constructor Description EmgRandomGenerator(IEolContext context)Instantiates a new emg random generator.EmgRandomGenerator(IEolContext context, long seed)Instantiates a new emg random generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.commons.math3.random.RandomDataGeneratorgetGenerator()java.util.List<java.lang.Integer>getIndex(java.lang.String listID, int size, java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> sampleList)protected java.util.List<java.lang.String>getValuesFromList(java.lang.String list)Gets the values from list.java.util.List<java.lang.Integer>nextAddTo(int n, int m)Returns an array of n integers that addvar to m.doublenextBinomialValue(int numberOfTrials, double probabilityOfSuccess)Generates a random value from the Binomial Distribution.booleannextBoolean()voidnextBytes(byte[] bytes)java.lang.StringnextCamelCaseString(int length, int minWordLength)Generates a random string of the given length using the specified character set formatted in CameCase format.java.lang.StringnextCapitalisedString(java.lang.String charSet, int length)Next capitalised string.doublenextDobule(double upper)Returns a pseudorandom, uniformly distributed double value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.doublenextDobule(double lower, double upper)Returns a pseudorandom, uniformly distributed double value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.doublenextDouble()doublenextExponentialValue(double mean)Generates a random value from the Exponential Distribution.floatnextFloat()java.lang.ObjectnextFromCollection(java.util.Collection<?> c)Returns a single object selected randomly from the Collection c using a uniform distribution.java.lang.ObjectnextFromList(java.lang.String listID)The listID must be the name of a parameter in the launch configuration.java.lang.ObjectnextFromListAsSample(java.lang.String listID)The listID must be the name of a parameter in the launch configuration.doublenextGaussian()java.lang.StringnextHttpURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment)Generates a random URI that complies to: http:[//host[:port]][/]path[?query][#fragment] The scheme is The host is generated from a random string and uses a top-level domain.intnextInt()intnextInt(int n)intnextInteger(int upper)Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.intnextInteger(int lower, int upper)Returns a pseudorandom, uniformly distributed int value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.longnextLong()longnextLong(long upper)Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.longnextLong(long lower, long upper)Returns a pseudorandom, uniformly distributed long value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.java.util.List<java.lang.Object>nextSample(java.lang.String listID, int k)The listID must be the name of a parameter in the launch configuration.java.util.List<java.lang.Object>nextSample(java.util.Collection<?> c, int k)Returns an array of k objects selected randomly from the Collection c using a uniform distribution.java.lang.StringnextString(java.lang.String charSet, int length)Generates a random string of the given length using the specified character set.java.lang.StringnextURI()Generates a random URI.java.lang.StringnextURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment)Generates a random URI that complies to: scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] The scheme is randomly selected from: http, ssh and ftp.doublenextValue()Returns the next pseudorandom, value from this random attribute generator's sequence.voidsetSeed(int seed)voidsetSeed(int[] seed)voidsetSeed(long seed)voiduseBinomialDistribution(int numberOfTrials, double probabilityOfSuccess)Use binomial distribution.voiduseExponentialDistribution(double mean)Use exponential distribution.
-
-
-
Constructor Detail
-
EmgRandomGenerator
public EmgRandomGenerator(IEolContext context)
Instantiates a new emg random generator.- Parameters:
context- the context
-
EmgRandomGenerator
public EmgRandomGenerator(IEolContext context, long seed)
Instantiates a new emg random generator.- Parameters:
context- the contextseed- the seed
-
-
Method Detail
-
getGenerator
public org.apache.commons.math3.random.RandomDataGenerator getGenerator()
- Returns:
- the generator
-
getIndex
public java.util.List<java.lang.Integer> getIndex(java.lang.String listID, int size, java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> sampleList) throws EolRuntimeException- Throws:
EolRuntimeException
-
nextAddTo
public java.util.List<java.lang.Integer> nextAddTo(int n, int m) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns an array of n integers that addvar to m.- Specified by:
nextAddToin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextBinomialValue
public double nextBinomialValue(int numberOfTrials, double probabilityOfSuccess)Description copied from interface:IEmgRandomGeneratorGenerates a random value from the Binomial Distribution.- Specified by:
nextBinomialValuein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
-
nextBoolean
public boolean nextBoolean()
- Specified by:
nextBooleanin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextBytes
public void nextBytes(byte[] bytes)
- Specified by:
nextBytesin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextCamelCaseString
public java.lang.String nextCamelCaseString(int length, int minWordLength) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorGenerates a random string of the given length using the specified character set formatted in CameCase format. Characters are picked from the LETTER set using a uniform distribution.- Specified by:
nextCamelCaseStringin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
length- the length- Returns:
- the string
- Throws:
EolRuntimeException
-
nextCapitalisedString
public java.lang.String nextCapitalisedString(java.lang.String charSet, int length)Description copied from interface:IEmgRandomGeneratorNext capitalised string.- Specified by:
nextCapitalisedStringin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
charSet- the char setlength- the length- Returns:
- the string
-
nextDobule
public double nextDobule(double upper) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns a pseudorandom, uniformly distributed double value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.- Specified by:
nextDobulein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextDobule
public double nextDobule(double lower, double upper)Description copied from interface:IEmgRandomGeneratorReturns a pseudorandom, uniformly distributed double value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.- Specified by:
nextDobulein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
-
nextDouble
public double nextDouble()
- Specified by:
nextDoublein interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextExponentialValue
public double nextExponentialValue(double mean)
Description copied from interface:IEmgRandomGeneratorGenerates a random value from the Exponential Distribution.- Specified by:
nextExponentialValuein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
-
nextFloat
public float nextFloat()
- Specified by:
nextFloatin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextFromCollection
public java.lang.Object nextFromCollection(java.util.Collection<?> c)
Description copied from interface:IEmgRandomGeneratorReturns a single object selected randomly from the Collection c using a uniform distribution.- Specified by:
nextFromCollectionin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- the t
-
nextFromList
public java.lang.Object nextFromList(java.lang.String listID) throws EolRuntimeExceptionThe listID must be the name of a parameter in the launch configuration. The value of the parameter can be either a CSV list of strings or the name of a file. The name of the file should be full path and each line in the file is considered a separate item.- Specified by:
nextFromListin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
listID- the listID- Returns:
- the t
- Throws:
EolRuntimeException- See Also:
IEmgRandomGenerator.nextFromList(java.lang.String)
-
nextFromListAsSample
public java.lang.Object nextFromListAsSample(java.lang.String listID) throws EolRuntimeExceptionThe listID must be the name of a parameter in the launch configuration. The value of the parameter can be either a CSV list of strings or the name of a file. The name of the file should be full path and each line in the file is considered a separate item.- Specified by:
nextFromListAsSamplein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException- See Also:
org.eclipse.epsilon.emg.random.IEmgRandomGenerator#nextSampleFromList(java.lang.String)
-
nextGaussian
public double nextGaussian()
- Specified by:
nextGaussianin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextHttpURI
public java.lang.String nextHttpURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorGenerates a random URI that complies to: http:[//host[:port]][/]path[?query][#fragment] The scheme is The host is generated from a random string and uses a top-level domain. The optional parameters will add additional information to the URI. The number of paths and queries are random between 1 and 4.- Specified by:
nextHttpURIin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextInt
public int nextInt()
- Specified by:
nextIntin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextInt
public int nextInt(int n)
- Specified by:
nextIntin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextInteger
public int nextInteger(int upper) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.- Specified by:
nextIntegerin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextInteger
public int nextInteger(int lower, int upper) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns a pseudorandom, uniformly distributed int value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.- Specified by:
nextIntegerin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextLong
public long nextLong()
- Specified by:
nextLongin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextLong
public long nextLong(long upper) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.- Specified by:
nextLongin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextLong
public long nextLong(long lower, long upper) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns a pseudorandom, uniformly distributed long value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.- Specified by:
nextLongin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextSample
public java.util.List<java.lang.Object> nextSample(java.util.Collection<?> c, int k) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorReturns an array of k objects selected randomly from the Collection c using a uniform distribution. Particular implementations need to define what a valid listID is and how the data associated with it will be retrieved. Sampling from c is without replacement; but if c contains identical objects, the sample may include repeats. If all elements of c are distinct, the resulting object collection represents a Simple Random Sample of size k from the elements of c.- Specified by:
nextSamplein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Throws:
EolRuntimeException
-
nextSample
public java.util.List<java.lang.Object> nextSample(java.lang.String listID, int k) throws EolRuntimeExceptionThe listID must be the name of a parameter in the launch configuration. The value of the parameter can be either a CSV list of strings or the name of a file. The name of the file should be full path and each line in the file is considered a separate item.- Specified by:
nextSamplein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Throws:
EolRuntimeException- See Also:
IEmgRandomGenerator.nextSample(java.lang.String, int)
-
nextString
public java.lang.String nextString(java.lang.String charSet, int length)Description copied from interface:IEmgRandomGeneratorGenerates a random string of the given length using the specified character set. Characters are picked from the set using a uniform distribution.- Specified by:
nextStringin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
-
nextURI
public java.lang.String nextURI() throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorGenerates a random URI. The port, path, query and fragment are added randomly.- Specified by:
nextURIin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextURI
public java.lang.String nextURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment) throws EolRuntimeExceptionDescription copied from interface:IEmgRandomGeneratorGenerates a random URI that complies to: scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] The scheme is randomly selected from: http, ssh and ftp. For ssh and ftp, a user and pasword are randomly generated. The host is generated from a random string and uses a top-level domain. The optional parameters will add additional information to the URI. The number of paths and queries are random between 1 and 4.- Specified by:
nextURIin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
- Throws:
EolRuntimeException
-
nextValue
public double nextValue()
Description copied from interface:IEmgRandomGeneratorReturns the next pseudorandom, value from this random attribute generator's sequence. The value is picked from the defined distribution.- Specified by:
nextValuein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Returns:
-
setSeed
public void setSeed(int seed)
- Specified by:
setSeedin interfaceorg.apache.commons.math3.random.RandomGenerator
-
setSeed
public void setSeed(int[] seed)
- Specified by:
setSeedin interfaceorg.apache.commons.math3.random.RandomGenerator
-
setSeed
public void setSeed(long seed)
- Specified by:
setSeedin interfaceorg.apache.commons.math3.random.RandomGenerator
-
useBinomialDistribution
public void useBinomialDistribution(int numberOfTrials, double probabilityOfSuccess)Use binomial distribution.- Parameters:
numberOfTrials- the number of trialsprobabilityOfSuccess- the probability of success
-
useExponentialDistribution
public void useExponentialDistribution(double mean)
Use exponential distribution.- Parameters:
mean- the mean
-
getValuesFromList
protected java.util.List<java.lang.String> getValuesFromList(java.lang.String list) throws EolRuntimeExceptionGets the values from list.- Parameters:
list- the list- Returns:
- the values from list
- Throws:
EolRuntimeException- the eol runtime exception
-
-