🎲 Random Number Generator for Gleam
https://gwg-rng.hexdocs.pm
- Gleam 98.9%
- Erlang 0.7%
- JavaScript 0.4%
| src |
docs: Updated examples to using assert.
|
|
| test |
feat: Removed hash function.
|
|
| .gitignore | first commit 🎉 | |
| gleam.toml |
docs: Updated examples to using assert.
|
|
| LICENSE | add LICENSE | |
| manifest.toml | 2026年02月23日T05:17:49.346+07:00 | |
| README.md | docs: Updated description. | |
gwg_rng
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: