Function floatSource

Returns a function that produces random float values. Use float to produce a valued directly.

Random float between max (exclusive) and 0 (inclusive). Max is 1 if unspecified.

// Random number between 0..1 (but not including 1)
// (this would be identical to Math.random())
const r = floatSource();
r(); // Execute to produce random value

// Random float between 0..100 (but not including 100)
const v = floatSource(100)();

Options can be used:

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

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

      Maximum value (exclusive) or options

    Returns RandomSource

    Random number