feat(utils): add a phonetic key generator
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
		
							parent
							
								
									13728f2ef8
								
							
						
					
					
						commit
						1b54edf7b3
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -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 | ||||||
							
								
								
									
										19
									
								
								lib/ketbin/pastes/utils.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								lib/ketbin/pastes/utils.ex
									
									
									
									
									
										Normal 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 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user