feat(utils): add a phonetic key generator

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2021-08-13 07:12:13 +05:30
1 parent 13728f2ef8
commit 1b54edf7b3
2 files changed
+20

No files matched your search

+19
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