Function float

Returns a random float between max (exclusive) and 0 (inclusive). Max is 1 if unspecified. Use floatSource to get a function that produces values. This is used internally.

// Random number between 0..1 (but not including 1)
// (this would be identical to Math.random())
const v = float();
// Random float between 0..100 (but not including 100)
const v = float(100);

Options can be used:

// Random float between 20..40 (possibly including 20, but always lower than 40)
const v = float({ min: 20, max: 40 });
  • Parameters

    • maxOrOptions: number | Readonly<{
          max: number;
          min?: number;
          source?: RandomSource;
      }> = 1

      Maximum value (exclusive) or options

    Returns number

    Random number