Class RandomFloat

java.lang.Object
org.pipservices3.commons.random.RandomFloat

public class RandomFloat extends Object
Random generator for float values.

### Example ###

 
 float value1 = RandomFloat.nextFloat(5, 10);     // Possible result: 7.3
 float value2 = RandomFloat.nextFloat(10);        // Possible result: 3.7
 float value3 = RandomFloat.updateFloat(10, 3);   // Possible result: 9.2
 
 
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    nextFloat(float min, float max)
    Generates a float in the range ['min', 'max'].
    static float
    nextFloat(int max)
    Generates a float in the range [0, 'max'].
    static float
    updateFloat(float value)
    Updates (drifts) a float value without specified range defined
    static float
    updateFloat(float value, float range)
    Updates (drifts) a float value within specified range defined

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RandomFloat

      public RandomFloat()
  • Method Details

    • nextFloat

      public static float nextFloat(int max)
      Generates a float in the range [0, 'max'].
      Parameters:
      max - (optional) maximum value of the float that will be generated.
      Returns:
      generated random float value.
    • nextFloat

      public static float nextFloat(float min, float max)
      Generates a float in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].
      Parameters:
      min - minimum value of the float that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
      max - (optional) maximum value of the float that will be generated. Defaults to 'min' if omitted.
      Returns:
      generated random float value.
    • updateFloat

      public static float updateFloat(float value)
      Updates (drifts) a float value without specified range defined
      Parameters:
      value - a float value to drift.
      Returns:
      updated random float value.
    • updateFloat

      public static float updateFloat(float value, float range)
      Updates (drifts) a float value within specified range defined
      Parameters:
      value - a float value to drift.
      range - (optional) a range. Default: 10% of the value
      Returns:
      updated random float value.