Skip to main content

random

Returns a floating-point random number within the specified range.

If a single argument is passed, it is treated as the maximum value, and the minimum value defaults to 0. If two arguments are passed, the first is used as the minimum and the second as the maximum.


Code

🔗 View source code


Benchmark

  • hz: operations per second
  • mean: average response time (ms)
NamehzmeanPerformance
modern-kit/random17,637,495.390.0001fastest
lodash/random8,151,192.010.0001-
  • modern-kit/random
    • 2.16x faster than lodash/random

Interface

typescript
// Function overloading
function random(maximum: number): number;
function random(minimum: number, maximum: number): number;

Usage

Basic Usage

typescript
import { random } from '@modern-kit/utils';

const result = random(10); // Returns a floating-point random number from 0 (inclusive) to 10 (exclusive)

With Range

typescript
import { random } from '@modern-kit/utils';

const result = random(5, 10); // Returns a floating-point random number from 5 (inclusive) to 10 (exclusive)