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.RandomDataGenerator
getValuesFromList
(String list) Gets the values from list.nextAddTo
(int n, int m) Returns an array of n integers that addvar to m.double
nextBinomialValue
(int numberOfTrials, double probabilityOfSuccess) Generates a random value from the Binomial Distribution.boolean
void
nextBytes
(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.double
nextDobule
(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.double
nextDobule
(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.double
double
nextExponentialValue
(double mean) Generates a random value from the Exponential Distribution.float
nextFromCollection
(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.double
nextHttpURI
(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.int
nextInt()
int
nextInt
(int n) int
nextInteger
(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.int
nextInteger
(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.long
nextLong()
long
nextLong
(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.long
nextLong
(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.double
Returns the next pseudorandom, value from this random attribute generator's sequence.void
setSeed
(int seed) void
setSeed
(int[] seed) void
setSeed
(long seed) void
useBinomialDistribution
(int numberOfTrials, double probabilityOfSuccess) Use binomial distribution.void
useExponentialDistribution
(double mean) Use exponential distribution.
-
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:IEmgRandomGenerator
Returns an array of n integers that addvar to m.- Specified by:
nextAddTo
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextBinomialValue
public double nextBinomialValue(int numberOfTrials, double probabilityOfSuccess) Description copied from interface:IEmgRandomGenerator
Generates a random value from the Binomial Distribution.- Specified by:
nextBinomialValue
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
-
nextBoolean
public boolean nextBoolean()- Specified by:
nextBoolean
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextBytes
public void nextBytes(byte[] bytes) - Specified by:
nextBytes
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextCamelCaseString
Description copied from interface:IEmgRandomGenerator
Generates 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:
nextCamelCaseString
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Parameters:
length
- the length- Returns:
- the string
- Throws:
EolRuntimeException
-
nextCapitalisedString
Description copied from interface:IEmgRandomGenerator
Next capitalised string.- Specified by:
nextCapitalisedString
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Parameters:
charSet
- the char setlength
- the length- Returns:
- the string
-
nextDobule
Description copied from interface:IEmgRandomGenerator
Returns a pseudorandom, uniformly distributed double value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.- Specified by:
nextDobule
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextDobule
public double nextDobule(double lower, double upper) Description copied from interface:IEmgRandomGenerator
Returns a pseudorandom, uniformly distributed double value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.- Specified by:
nextDobule
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
-
nextDouble
public double nextDouble()- Specified by:
nextDouble
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextExponentialValue
public double nextExponentialValue(double mean) Description copied from interface:IEmgRandomGenerator
Generates a random value from the Exponential Distribution.- Specified by:
nextExponentialValue
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
-
nextFloat
public float nextFloat()- Specified by:
nextFloat
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextFromCollection
Description copied from interface:IEmgRandomGenerator
Returns a single object selected randomly from the Collection c using a uniform distribution.- Specified by:
nextFromCollection
in 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:
nextFromList
in 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:
nextFromListAsSample
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
- See Also:
-
org.eclipse.epsilon.emg.random.IEmgRandomGenerator#nextSampleFromList(java.lang.String)
-
nextGaussian
public double nextGaussian()- Specified by:
nextGaussian
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextHttpURI
public String nextHttpURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment) throws EolRuntimeException Description copied from interface:IEmgRandomGenerator
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. The optional parameters will add additional information to the URI. The number of paths and queries are random between 1 and 4.- Specified by:
nextHttpURI
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextInt
public int nextInt()- Specified by:
nextInt
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextInt
public int nextInt(int n) - Specified by:
nextInt
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextInteger
Description copied from interface:IEmgRandomGenerator
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.- Specified by:
nextInteger
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextInteger
Description copied from interface:IEmgRandomGenerator
Returns a pseudorandom, uniformly distributed int value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.- Specified by:
nextInteger
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextLong
public long nextLong()- Specified by:
nextLong
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
nextLong
Description copied from interface:IEmgRandomGenerator
Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random attribute generator's sequence.- Specified by:
nextLong
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextLong
Description copied from interface:IEmgRandomGenerator
Returns a pseudorandom, uniformly distributed long value between lower and upper (endpoints included), drawn from this random attribute generator's sequence.- Specified by:
nextLong
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextSample
Description copied from interface:IEmgRandomGenerator
Returns 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:
nextSample
in 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:
nextSample
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Throws:
EolRuntimeException
- See Also:
-
nextString
Description copied from interface:IEmgRandomGenerator
Generates a random string of the given length using the specified character set. Characters are picked from the set using a uniform distribution.- Specified by:
nextString
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
-
nextURI
Description copied from interface:IEmgRandomGenerator
Generates a random URI. The port, path, query and fragment are added randomly.- Specified by:
nextURI
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextURI
public String nextURI(boolean addPort, boolean addPath, boolean addQuery, boolean addFragment) throws EolRuntimeException Description copied from interface:IEmgRandomGenerator
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. 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:
nextURI
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
- Throws:
EolRuntimeException
-
nextValue
public double nextValue()Description copied from interface:IEmgRandomGenerator
Returns the next pseudorandom, value from this random attribute generator's sequence. The value is picked from the defined distribution.- Specified by:
nextValue
in interfaceIEmgRandomGenerator<IEmgRandomGenerator.DefaultCharacterSet>
- Returns:
-
setSeed
public void setSeed(int seed) - Specified by:
setSeed
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
setSeed
public void setSeed(int[] seed) - Specified by:
setSeed
in interfaceorg.apache.commons.math3.random.RandomGenerator
-
setSeed
public void setSeed(long seed) - Specified by:
setSeed
in 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
-