README.md

# gwg_rng

[![Package Version](https://img.shields.io/hexpm/v/gwg_rng)](https://hex.pm/packages/gwg_rng)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gwg_rng/)

This is a Random Number Generator (RNG) library for the [Gleam programming language](https://gleam.run).

This package is a fork of [`prng`](https://hexdocs.pm/prng).

This package can help you generate any kind of random values you can think of.
It can be useful in many different scenarios: when you need to simulate
non-deterministic actions, like rolling a dice or flipping a coin; when you need
to write [property based tests](https://ferd.ca/property-based-testing-basics.html);
or to make fun interactive games where you can spawn randomly generated enemies!

> This package and its documentation are based on the awesome
> [Elm implementation](https://package.elm-lang.org/packages/elm/random/1.0.0)
> of [Permuted Congruential Generators](https://www.pcg-random.org).
> They have great documentation full of clear and useful examples; if you are
> curious, give it a look and show Elm some love!

## Installation

```sh
gleam add gwg_rng
```

```gleam
import gwg/rng/random

pub fn main() {
  // A generator describes which kind of random values to produce:
  let generator = random.int(0, 10)

  // One can take values out of a generator using the `step` function.
  // Using the same initial seed will always produce the same value!
  let #(value, _) = random.step(generator, random.new(11))
  assert value == 10
  let #(other_value, _) = random.step(generator, random.new(11))
  assert other_value == 10

  // The `step` function also produces a new seed you can use on successive
  // calls to generate a new pseudo-random value each time you call it:
  let #(value, next_seed) = random.step(generator, random.new(11))
  assert value == 10
  let #(other_value, _) = random.step(generator, next_seed)
  assert other_value == 4
}
```

Further documentation can be found at <https://hexdocs.pm/gwg_rng>.

## Credits

Special thanks to:

- [**PRNG**](https://hexdocs.pm/prng)
- [**Permuted Congruential Generators**](https://www.pcg-random.org)
- [**Elm**](https://package.elm-lang.org)