Fab.Number (fab v1.1.0)

Functions for generating random numbers.

Summary

Functions

Returns a random float.

Returns a random hexadecimal.

Returns a random integer.

Functions

float(opts \\ [])

(since 1.0.0)
@spec float(number() | keyword()) :: float()

Returns a random float.

Options

  • :min - Lower bound of the generated float. Defaults to 0.0.
  • :max - Upper bound of the generated float. Defaults to 1.0.
  • :precision - Number of digits after the decimal point. Defaults to 1.

Examples

iex> Fab.Number.float()
0.2

iex> Fab.Number.float(5.0)
1.1

iex> Fab.Number.float(min: 1.0, max: 2.0)
1.2

iex> Fab.Number.float(precision: 3)
0.217

hex(opts \\ [])

(since 1.1.0)
@spec hex(number() | keyword()) :: String.t()

Returns a random hexadecimal.

Options

  • :min - Lower bound of the generated hexadecimal. Defaults to 0.
  • :max - Lower bound of the generated hexadecimal. Defaults to 15.

Examples

iex> Fab.Number.hex()
"F"

iex> Fab.Number.hex(255)
"7F"

iex> Fab.Number.hex(min: 0, max: 65535)
"467F"

integer(opts \\ [])

(since 1.0.0)
@spec integer(pos_integer() | keyword()) :: integer()

Returns a random integer.

Options

  • :min - Lower bound of the generated integer. Defaults to 0.
  • :max - Upper bound of the generated integer. Defaults to 9007199254740991.

Examples

iex> Fab.Number.integer()
3630114979716424

iex> Fab.Number.integer(1000)
340

iex> Fab.Number.integer(min: 1, max: 1000)
185