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 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
ConstructorsConstructorDescriptionEmgRandomGenerator(IEolContext context) Instantiates a new emg random generator.EmgRandomGenerator(IEolContext context, long seed) Instantiates a new emg random generator. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.commons.math3.random.RandomDataGeneratorgetValuesFromList(String list) Gets the values from list.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.booleanvoidnextBytes(byte[] bytes) nextCamelCaseString(int length, int minWordLength) Generates a random string of the given length using the specified character set formatted in CameCase format.nextCapitalisedString(String charSet, int length) Next capitalised string.doubledoublenextDouble(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.doublenextDouble(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.doublenextExponentialValue(double mean) Generates a random value from the Exponential Distribution.floatnextFromCollection(Collection<?> c) Returns a single object selected randomly from the Collection c using a uniform distribution.nextFromList(String listID) The listID must be the name of a parameter in the launch configuration.nextFromListAsSample(String listID) The listID must be the name of a parameter in the launch configuration.doublenextHttpURI(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.nextSample(String listID, int k) The listID must be the name of a parameter in the launch configuration.nextSample(Collection<?> c, int k) Returns an array of k objects selected randomly from the Collection c using a uniform distribution.nextString(String charSet, int length) Generates a random string of the given length using the specified character set.nextURI()Generates a random URI.nextURI(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.doubleReturns 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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.epsilon.emg.random.IEmgRandomGenerator
nextDobule, nextDobule
-
Constructor Details
-
EmgRandomGenerator
Instantiates a new emg random generator.- Parameters:
context- the context
-
EmgRandomGenerator
Instantiates a new emg random generator.- Parameters:
context- the contextseed- the seed
-
-
Method Details
-
getGenerator
public org.apache.commons.math3.random.RandomDataGenerator getGenerator()- Returns:
- the generator
-
getIndex
public List<Integer> getIndex(String listID, int size, Map<String, List<Integer>> sampleList) throws EolRuntimeException- Throws:
EolRuntimeException
-
nextAddTo
Description copied from interface:IEmgRandomGeneratorReturns an array of n integers that addvar to m.- Specified by:
nextAddToin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
n-m-- 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
Description 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
Description copied from interface:IEmgRandomGeneratorNext capitalised string.- Specified by:
nextCapitalisedStringin interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
charSet- the char setlength- the length- Returns:
- the string
-
nextDouble
Description 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:
nextDoublein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
upper-- Returns:
- Throws:
EolRuntimeException
-
nextDouble
public double nextDouble(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:
nextDoublein interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>- Parameters:
lower-upper-- 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
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
The 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:
-
nextFromListAsSample
The 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>- Parameters:
listID-- Returns:
- Throws:
EolRuntimeException- See Also:
-
nextGaussian
public double nextGaussian()- Specified by:
nextGaussianin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextHttpURI
public String nextHttpURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment) throws EolRuntimeException Description 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>- Parameters:
addPort-addPath-addQuery-addFragment-- 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
Description 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>- Parameters:
upper-- Returns:
- Throws:
EolRuntimeException
-
nextInteger
Description 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>- Parameters:
lower-upper-- Returns:
- Throws:
EolRuntimeException
-
nextLong
public long nextLong()- Specified by:
nextLongin interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextLong
Description 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>- Parameters:
upper-- Returns:
- Throws:
EolRuntimeException
-
nextLong
Description 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>- Parameters:
lower-upper-- Returns:
- Throws:
EolRuntimeException
-
nextSample
Description 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
The 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:
-
nextString
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>- Parameters:
charSet-length-- Returns:
-
nextURI
Description 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 String nextURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment) throws EolRuntimeException Description 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>- Parameters:
addPort-addPath-addQuery-addFragment-- 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
Gets the values from list.- Parameters:
list- the list- Returns:
- the values from list
- Throws:
EolRuntimeException- the eol runtime exception
-