NeoFaker.Number (neo_faker v0.9.0)

View Source

Functions for generating random numbers.

This module provides utilities to generate random numbers, including values within a specified range.

Summary

Functions

Generates a random number between min and max.

Generates a random digit between 0 and 9.

Generates a random floating-point number within the given range.

Functions

between(min \\ 0, max \\ 100)

(since 0.8.0)
@spec between(number(), number()) :: number()

Generates a random number between min and max.

If both arguments are integers, the result is a random integer within the range. If they are floats, a random float within the range is returned.

Examples

iex> NeoFaker.Number.between()
27

iex> NeoFaker.Number.between(1, 100)
28

iex> NeoFaker.Number.between(1.0, 100.0)
29.481745280074264

digit()

(since 0.8.0)
@spec digit() :: integer()

Generates a random digit between 0 and 9.

Examples

iex> NeoFaker.Number.digit()
5

float(left_digit \\ 10..100, right_digit \\ 10000..100_000)

(since 0.8.0)
@spec float(Range.t(), Range.t()) :: float()

Generates a random floating-point number within the given range.

The integer part is selected from left_digit, and the fractional part from right_digit. Both arguments are ranges, and the function returns a float by combining a random value from each.

Examples

iex> NeoFaker.Number.float()
30.94372

iex> NeoFaker.Number.float(1..9, 10..90)
1.44