feat(utils): add a phonetic key generator

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2021-08-13 07:12:13 +05:30
parent 13728f2ef8
commit 1b54edf7b3
No known key found for this signature in database
GPG Key ID: ED5C54FBBB920E51
2 changed files with 20 additions and 0 deletions

1
.gitignore vendored
View File

@ -32,3 +32,4 @@ npm-debug.log
# we ignore priv/static. You may want to comment # we ignore priv/static. You may want to comment
# this depending on your deployment strategy. # this depending on your deployment strategy.
/priv/static/ /priv/static/
.idea

View File

@ -0,0 +1,19 @@
defmodule Ketbin.Pastes.Utils do
defp rand_vowel do
String.graphemes("aeiou")
|> Enum.take_random(1)
|> Enum.at(0)
end
defp rand_consonant do
String.graphemes("bcdfghjklmnpqrstvwxyz")
|> Enum.take_random(1)
|> Enum.at(0)
end
def generate_key(length \\ 10) do
random = Enum.random([0, 1])
Enum.map(0..length, fn i -> if Integer.mod(i, 2) == random, do: rand_consonant(), else: rand_vowel() end)
|> List.to_string
end
end