Get Random Float
Generates a random floating-point number within a specified range.
getRandomFloat
The getRandomFloat function generates a random floating-point number within a specified range (inclusive of min, exclusive of max). It's useful for simulations, statistical sampling, and any scenario requiring precise random decimal values.
Function Signature
function getRandomFloat(min: Numeric, max: Numeric): numberParameters
min(Numeric): The lower bound (inclusive) - can be a number or numeric string.max(Numeric): The upper bound (exclusive) - can be a number or numeric string.
Return Value
number: A random floating-point number wheremin≤ value <max.
Example Usage
playground.ts
Notes
- Inclusive/Exclusive: The minimum is inclusive, while the maximum is exclusive (matching native
Math.random()behavior). - Numeric Conversion: Automatically converts numeric strings to numbers.
- Edge Cases: If
minequalsmax, it returnsmin. Ifmin>max, the values are swapped internally.
Types
Numeric
type Numeric = number | `${number}`;Aliases
getRandomDecimal
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
