Create Heroku-like names randomly, or consistently (based on inputs).
Add anonymous_name_generator
to your list of dependencies in mix.exs
:
def deps do
[
{:anonymous_name_generator, "~> 0.1"}
]
end
Documentation can be found at https://hexdocs.pm/anonymous_name_generator.
These are used to generate a random name. The default number of possibilities is ~138,000. If you need more, add an integer to include a number along with the name.
generate_random()
=> "slushy-billboard"
generate_random()
=> "clumsy-lamb"
generate_random(100_000)
=> "weak-jewel"
generate_random(1_000_000_000)
=> "powerful-emu-1455"
These are using if you want predictable/consistent names. For example if you want to add names to users, you could pick any two integers for that user (e.g. ID, and inserted_at unix timestamp).
user = %User{id: 123, timestamp: 1533440961}
generate_consistent(user.id, user.timestamp)
=> "massive-motel"
generate_consistent(user.id, user.timestamp, 1_000_000_000)
=> "massive-motel-5472"
Every time you call generate_consistent/2
/generate_consistent/3
with the same input, it'll return the same output.
MIT
- Initial Release
- sped up generate_random by using
:rand.uniform
instead ofEnum.random
- Added
@moduledoc false
tonoun.ex
andadjective.ex
- Fix typo
- Performance boost by switching from noun/adj. using lists and
Enum.at/2
, to usingelem/2
and tuples.