# `NeoFaker.Number`
[🔗](https://github.com/muzhawir/neo_faker/blob/main/lib/neo_faker/number.ex#L1)

Functions for generating random numbers.

Provides utilities to generate random integers, floats, digits, and decimals, including
values within a specified range and numbers with controlled precision.

# `between`
*since 0.8.0* 

```elixir
@spec between(number(), number()) :: number()
```

Generates a random number between `min` and `max`.

Returns an integer when both arguments are integers, or a float when either argument is a
float. Defaults to the range `0`–`100`.

## Parameters

- `min` - Minimum value (inclusive). Defaults to `0`.
- `max` - Maximum value (inclusive). Defaults to `100`.

## Examples

    iex> NeoFaker.Number.between()
    27

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

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

    iex> NeoFaker.Number.between(50, 50)
    50

    iex> NeoFaker.Number.between(100, 1)
    ** (ArgumentError) min must be less than or equal to max, got: min=100, max=1

# `decimal`
*since 0.8.0* 

```elixir
@spec decimal(number(), number(), non_neg_integer()) :: float()
```

Generates a random float rounded to the specified number of decimal places.

## Parameters

- `min` - Minimum value (inclusive). Defaults to `0.0`.
- `max` - Maximum value (inclusive). Defaults to `100.0`.
- `precision` - Number of decimal places. Defaults to `2`.

## Examples

    iex> NeoFaker.Number.decimal(0.0, 10.0, 2)
    5.47

    iex> NeoFaker.Number.decimal(0.0, 1.0, 4)
    0.7384

    iex> NeoFaker.Number.decimal()
    42.73

    iex> NeoFaker.Number.decimal(100.0, 0.0)
    ** (ArgumentError) min must be less than or equal to max, got: min=100.0, max=0.0

# `digit`
*since 0.8.0* 

```elixir
@spec digit() :: integer()
```

Generates a random single digit between `0` and `9`.

## Examples

    iex> NeoFaker.Number.digit()
    5

# `float`
*since 0.8.0* 

```elixir
@spec float(Range.t(), Range.t()) :: float()
```

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

Combines a randomly selected integer part from `left_digit` and a fractional part from
`right_digit` into a float. Defaults to `10..100` for the integer part and
`10_000..100_000` for the fractional part.

## Parameters

- `left_digit` - Range for the integer part. Defaults to `10..100`.
- `right_digit` - Range for the fractional part. Defaults to `10_000..100_000`.

## Examples

    iex> NeoFaker.Number.float()
    30.94372

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

    iex> NeoFaker.Number.float(10..5, 10..100)
    ** (ArgumentError) left_digit range must have first <= last, got: 10..5

# `negative`
*since 0.8.0* 

```elixir
@spec negative(neg_integer()) :: neg_integer()
```

Generates a random negative integer between `min` and `-1`.

## Parameters

- `min` - Minimum value (inclusive). Defaults to `-100`.

## Examples

    iex> NeoFaker.Number.negative(-50)
    -27

    iex> NeoFaker.Number.negative()
    -42

# `positive`
*since 0.8.0* 

```elixir
@spec positive(pos_integer()) :: pos_integer()
```

Generates a random positive integer between `1` and `max`.

## Parameters

- `max` - Maximum value (inclusive). Defaults to `100`.

## Examples

    iex> NeoFaker.Number.positive(50)
    27

    iex> NeoFaker.Number.positive()
    42

    iex> NeoFaker.Number.positive(0)
    ** (ArgumentError) max must be at least 1, got: 0

---

*Consult [api-reference.md](api-reference.md) for complete listing*
