minigen

Pure random data generation library, appropriate for realistic simulations in the Erlang ecosystem.

Installation

{deps, [
    {minigen, "0.1.1"}
]}.
defp deps do
  [
    {:minigen, "~> 0.1.1", manager: :rebar3}
  ]
end

Usage

The examples below use the run function that will probably return different values on each call. If we want to get the same values on each call, we need to use run_with_seed instead.

Don’t forget to visit https://hexdocs.pm/minigen/minigen.html to see the signature of the available functions: list, then, always, sequence, map, map2, map3, map4, map5. Their combination can generate values for any data type.

More examples can be found in the test directory of the GitHub repository.

Erlang examples

GEN=minigen:float(),
minigen:run(GEN).
0.7938520785840248
GEN=minigen:integer(10),
minigen:run(GEN).
4
GEN=minigen:boolean(),
minigen:run(GEN).
true
GEN=minigen:element_of_list([1, 2, 3]),
minigen:run(GEN).
{ok,2}
GEN=minigen:element_of_list([]),
minigen:run(GEN).
{error,nil}
GEN=minigen:shuffled_list([1, 2, 3]),
minigen:run(GEN).
[2,1,3]
GEN=minigen:string(6),
minigen:run(GEN).
"3Rzpqd"

Elixir examples

:minigen.float
|> :minigen.run
0.36087782004967894
:minigen.integer(10)
|> :minigen.run
8
:minigen.boolean
|> :minigen.run
false
:minigen.element_of_list(["a", "b", "c", "d"])
|> :minigen.run
{:ok, "c"}
:minigen.element_of_list([])
|> :minigen.run
{:error, nil}
:minigen.shuffled_list(["a", "b", "c", "d"])
|> :minigen.run
["c", "d", "b", "a"]
:minigen.string(7)
|> :minigen.run
"eJKp8sc"

Gleam examples

import minigen
minigen.float()
|> minigen.run
0.16296012690374562
minigen.integer(10)
|> minigen.run
6
minigen.boolean()
|> minigen.run
True
minigen.element_of_list([0.5348931595479329, 0.47372875562526207, 0.7109364198110805])
|> minigen.run
Ok(0.7109364198110805)
minigen.element_of_list([])
|> minigen.run
Error(Nil)
minigen.shuffled_list([0.5348931595479329, 0.47372875562526207, 0.7109364198110805])
|> minigen.run
[0.47372875562526207, 0.5348931595479329, 0.7109364198110805]
minigen.string(8)
|> minigen.run
"U3j641WL"
Search Document