/** * Returns a random element from the provided array. * * @param among the array to choose a random element from. * @return a random element of the provided array. */ public <T> T among( T[] among ) { return among[generator.nextInt( among.length )]; }
/** * @see RandomValues */ public int nextInt() { return generator.nextInt(); }
/** * Returns the next {@code int} between 0 (inclusive) and the specified value (exclusive) * * @param bound the upper bound (exclusive). Must be positive. * @return {@code int} * @see RandomValues */ public int nextInt( int bound ) { return generator.nextInt( bound ); }
/** * Returns an {@code int} between the given lower bound (inclusive) and the upper bound (inclusive) * * @param min minimum value that can be chosen (inclusive) * @param max maximum value that can be chosen (inclusive) * @return an {@code int} in the given inclusive range. * @see RandomValues */ public int intBetween( int min, int max ) { return min + generator.nextInt( max - min + 1 ); }
/** * Returns a random element of the provided list * * @param among the list to choose a random element from * @return a random element of the provided list */ public <T> T among( List<T> among ) { return among.get( generator.nextInt( among.size() ) ); }
/** * Returns the next {@link ByteValue} between 0 (inclusive) and the specified value (exclusive) * * @param bound the upper bound (exclusive). Must be positive. * @return {@link ByteValue} */ public ByteValue nextByteValue( byte bound ) { return byteValue( (byte) generator.nextInt( bound ) ); }
/** * @see RandomValues */ public ByteValue nextByteValue() { return byteValue( (byte) generator.nextInt() ); }
/** * Returns the next {@link IntValue} between 0 (inclusive) and the specified value (exclusive) * * @param bound the upper bound (exclusive). Must be positive. * @return {@link IntValue} * @see RandomValues */ public IntValue nextIntValue( int bound ) { return intValue( generator.nextInt( bound ) ); }
/** * Returns the next {@link ShortValue} between 0 (inclusive) and the specified value (exclusive) * * @param bound the upper bound (exclusive). Must be positive. * @return {@link ShortValue} */ public ShortValue nextShortValue( short bound ) { return shortValue( (short) generator.nextInt( bound ) ); }
/** * @see RandomValues */ public ShortValue nextShortValue() { return shortValue( (short) generator.nextInt() ); }
/** * @see RandomValues */ public IntValue nextIntValue() { return intValue( generator.nextInt() ); }
/** * @see RandomValues */ public int[] nextIntArrayRaw( int minLength, int maxLength ) { int length = intBetween( minLength, maxLength ); int[] ints = new int[length]; for ( int i = 0; i < length; i++ ) { ints[i] = generator.nextInt(); } return ints; }
/** * @see RandomValues */ public short[] nextShortArrayRaw( int minLength, int maxLength ) { int length = intBetween( minLength, maxLength ); short[] shorts = new short[length]; for ( int i = 0; i < length; i++ ) { shorts[i] = (short) generator.nextInt(); } return shorts; }
int diff = min == max ? 0 : generator.nextInt( max - min ); int length = min + diff; T[] result = (T[]) Array.newInstance( among.getClass().getComponentType(), length );
/** * @return next code point limited to the alpha numeric characters. */ private int alphaNumericCodePoint() { int nextInt = generator.nextInt( 4 ); if ( nextInt == 0 ) { return intBetween( 'A', 'Z' ); } else if ( nextInt == 1 ) { return intBetween( 'a', 'z' ); } else { //We want digits being roughly as frequent as letters return intBetween( '0', '9' ); } }
/** * @return the next random {@link PointArray}. * @see RandomValues */ public PointArray nextPointArray() { int nextInt = generator.nextInt( 4 ); switch ( nextInt ) { case 0: return nextCartesianPointArray(); case 1: return nextCartesian3DPointArray(); case 2: return nextGeographicPointArray(); case 3: return nextGeographic3DPointArray(); default: throw new IllegalStateException( nextInt + " not a valid point type" ); } }
/** * Returns a randomly selected point value spread uniformly over the supported types of points. * * @return a randomly selected point value */ public PointValue nextPointValue() { int nextInt = generator.nextInt( 4 ); switch ( nextInt ) { case 0: return nextCartesianPoint(); case 1: return nextCartesian3DPoint(); case 2: return nextGeographicPoint(); case 3: return nextGeographic3DPoint(); default: throw new IllegalStateException( nextInt + " not a valid point type" ); } }
/** * @see RandomValues */ public NumberValue nextNumberValue() { int type = generator.nextInt( 6 ); switch ( type ) { case 0: return nextByteValue(); case 1: return nextShortValue(); case 2: return nextIntValue(); case 3: return nextLongValue(); case 4: return nextFloatValue(); case 5: return nextDoubleValue(); default: throw new IllegalArgumentException( "Unknown value type " + type ); } }
/** * Returns a randomly selected temporal value spread uniformly over the supported types. * * @return a randomly selected temporal value */ public Value nextTemporalValue() { int nextInt = generator.nextInt( 6 ); switch ( nextInt ) { case 0: return nextDateValue(); case 1: return nextLocalDateTimeValue(); case 2: return nextDateTimeValue(); case 3: return nextLocalTimeValue(); case 4: return nextTimeValue(); case 5: return nextDuration(); default: throw new IllegalArgumentException( nextInt + " not a valid temporal type" ); } }