/** * Randomize a {@code float} value between 0.0 (inclusive) and the specified value (exclusive). */ public float nextFloat(float f) { return nextFloat(f, false); }
/** * Randomize a {@code float} value in the given range [min, max]. */ public float nextFloat(float min, float max) { if (min > max) { throw new IllegalArgumentException(MIN_MAX_ERROR); } return min + nextFloat(max - min, true); }
/** * Randomize a {@code float} value between 0.0 (inclusive) and the specified value (inclusive or exclusive as * required). * * @param inclusive * Whether or not, the returned value should include the given one. */ public float nextFloat(float f, boolean inclusive) { if (f <= 0.0F) { throw new IllegalArgumentException("f must be greater than 0!"); } // Randomize a float float rand = nextFloat(); // If the returned value should not include the given one, // make sure that the randomized float is not exactly 1.0 if (!inclusive) { while (rand == 1.0F) { rand = nextFloat(); } } return rand * f; }