Skip to content

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

Notifications You must be signed in to change notification settings

mrdimosthenis/minigen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minigen

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

Installation

  • For Erlang projects, add the dependency into rebar.config:
{deps, [
    {minigen, "0.1.1"}
]}.
  • For Elixir projects, add the dependency into mix.exs:
defp deps do
  [
    {:minigen, "~> 0.1.1", manager: :rebar3}
  ]
end
  • For Gleam projects, run gleam add minigen.

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

  • Create a random float number
GEN=minigen:float(),
minigen:run(GEN).
0.7938520785840248
  • Create a random integer number
GEN=minigen:integer(10),
minigen:run(GEN).
4
  • Create a random boolean value
GEN=minigen:boolean(),
minigen:run(GEN).
true
  • Get a random element from a list
GEN=minigen:element_of_list([1, 2, 3]),
minigen:run(GEN).
{ok,2}
GEN=minigen:element_of_list([]),
minigen:run(GEN).
{error,nil}
  • Shuffle a list
GEN=minigen:shuffled_list([1, 2, 3]),
minigen:run(GEN).
[2,1,3]
  • Create a random string
GEN=minigen:string(6),
minigen:run(GEN).
"3Rzpqd"

Elixir examples

  • Create a random float number
:minigen.float
|> :minigen.run
0.36087782004967894
  • Create a random integer number
:minigen.integer(10)
|> :minigen.run
8
  • Create a random boolean value
:minigen.boolean
|> :minigen.run
false
  • Get a random element from a list
:minigen.element_of_list(["a", "b", "c", "d"])
|> :minigen.run
{:ok, "c"}
:minigen.element_of_list([])
|> :minigen.run
{:error, nil}
  • Shuffle a list
:minigen.shuffled_list(["a", "b", "c", "d"])
|> :minigen.run
["c", "d", "b", "a"]
  • Create a random string
:minigen.string(7)
|> :minigen.run
"eJKp8sc"

Gleam examples

import minigen
  • Create a random float number
minigen.float()
|> minigen.run
0.16296012690374562
  • Create a random integer number
minigen.integer(10)
|> minigen.run
6
  • Create a random boolean value
minigen.boolean()
|> minigen.run
True
  • Get a random element from a list
minigen.element_of_list([0.5348931595479329, 0.47372875562526207, 0.7109364198110805])
|> minigen.run
Ok(0.7109364198110805)
minigen.element_of_list([])
|> minigen.run
Error(Nil)
  • Shuffle a list
minigen.shuffled_list([0.5348931595479329, 0.47372875562526207, 0.7109364198110805])
|> minigen.run
[0.47372875562526207, 0.5348931595479329, 0.7109364198110805]
  • Create a random string
minigen.string(8)
|> minigen.run
"U3j641WL"

About

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

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •