gwg/rng
2
0
Fork
You've already forked rng
0
🎲 Random Number Generator for Gleam https://gwg-rng.hexdocs.pm
  • Gleam 98.9%
  • Erlang 0.7%
  • JavaScript 0.4%
2026年06月06日 13:27:14 +07:00
src docs: Updated examples to using assert. 2026年06月06日 13:27:14 +07:00
test feat: Removed hash function. 2026年03月30日 20:16:01 +07:00
.gitignore first commit 🎉 2023年09月14日 19:46:51 +02:00
gleam.toml docs: Updated examples to using assert. 2026年06月06日 13:27:14 +07:00
LICENSE add LICENSE 2023年09月25日 08:54:06 +02:00
manifest.toml 2026年02月23日T05:17:49.346+07:00 2026年02月23日 05:17:49 +07:00
README.md docs: Updated description. 2026年03月31日 00:59:23 +07:00

gwg_rng

Package Version Hex Docs

This is an alternative API, wrapped around the prng library.

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; 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 of Permuted Congruential Generators. They have great documentation full of clear and useful examples; if you are curious, give it a look and show Elm some love!

Installation

gleam add gwg_rng
importgwg/rng/randompubfnmain(){// A generator describes which kind of random values to produce:
letgenerator=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))assertvalue==10let#(other_value,_)=random.step(generator,random.new(11))assertother_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))assertvalue==10let#(other_value,_)=random.step(generator,next_seed)assertother_value==4}

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

Credits

Special thanks to: