Package org.h2.test.synth.sql
Class RandomGen
- java.lang.Object
-
- org.h2.test.synth.sql.RandomGen
-
public class RandomGen extends java.lang.ObjectA random data generator class.
-
-
Constructor Summary
Constructors Constructor Description RandomGen()Create a new random instance with a fixed seed value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetBoolean(int percent)Get a boolean that is true with the given probability in percent.byte[]getByteArray()Get a random byte array.voidgetBytes(byte[] data)Get a number of random bytes.intgetInt(int max)Get the next integer that is smaller than max.int[]getIntArray()Get a random integer array.intgetLog(int max)Get the next random value that is at most max but probably much lower.doublegetRandomDouble()Get a random double.intgetRandomInt()Get a random integer.longgetRandomLong()Get a random long.java.lang.Stringmodify(java.lang.String sql)Randomly modify a SQL statement.booleannextBoolean()Get a random boolean.doublenextGaussian()Get the next gaussian value.java.sql.DaterandomDate()Get a random date value.java.lang.StringrandomString(int len)Get a random string with the given length.java.sql.TimerandomTime()Get a random time value.java.sql.TimestamprandomTimestamp()Get a random timestamp value.voidsetSeed(int seed)Set the seed value.
-
-
-
Method Detail
-
getInt
public int getInt(int max)
Get the next integer that is smaller than max.- Parameters:
max- the upper limit (exclusive)- Returns:
- the random value
-
nextGaussian
public double nextGaussian()
Get the next gaussian value.- Returns:
- the value
-
getLog
public int getLog(int max)
Get the next random value that is at most max but probably much lower.- Parameters:
max- the maximum value- Returns:
- the value
-
getBytes
public void getBytes(byte[] data)
Get a number of random bytes.- Parameters:
data- the target buffer
-
getBoolean
public boolean getBoolean(int percent)
Get a boolean that is true with the given probability in percent.- Parameters:
percent- the probability- Returns:
- the boolean value
-
randomString
public java.lang.String randomString(int len)
Get a random string with the given length.- Parameters:
len- the length- Returns:
- the string
-
getRandomInt
public int getRandomInt()
Get a random integer. In 10% of the cases, Integer.MAX_VALUE is returned, in 10% of the cases Integer.MIN_VALUE. Also in the 10% of the cases, a random value between those extremes is returned. In 20% of the cases, this method returns 0. In 10% of the cases, a gaussian value in the range -200 and +1800 is returned. In all other cases, a gaussian value in the range -5 and +20 is returned.- Returns:
- the random value
-
getRandomLong
public long getRandomLong()
Get a random long. The algorithm is similar to a random int.- Returns:
- the random value
-
getRandomDouble
public double getRandomDouble()
Get a random double. The algorithm is similar to a random int.- Returns:
- the random value
-
nextBoolean
public boolean nextBoolean()
Get a random boolean.- Returns:
- the random value
-
getIntArray
public int[] getIntArray()
Get a random integer array. In 10% of the cases, null is returned.- Returns:
- the array
-
getByteArray
public byte[] getByteArray()
Get a random byte array. In 10% of the cases, null is returned.- Returns:
- the array
-
randomTime
public java.sql.Time randomTime()
Get a random time value. In 10% of the cases, null is returned.- Returns:
- the value
-
randomTimestamp
public java.sql.Timestamp randomTimestamp()
Get a random timestamp value. In 10% of the cases, null is returned.- Returns:
- the value
-
randomDate
public java.sql.Date randomDate()
Get a random date value. In 10% of the cases, null is returned.- Returns:
- the value
-
modify
public java.lang.String modify(java.lang.String sql)
Randomly modify a SQL statement.- Parameters:
sql- the original SQL statement- Returns:
- the modified statement
-
setSeed
public void setSeed(int seed)
Set the seed value.- Parameters:
seed- the new seed value
-
-