- Notifications
You must be signed in to change notification settings - Fork0
A Elixir module to generate a random string based on a given string pattern.
License
caioceccon/random_string_generator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A module to generate a random string based on a given string pattern
The package can be installed by addingrandom_string_generator
to your list of dependencies inmix.exs
:
defdepsdo[{:random_string_generator,"~> 1.0.0"}]end
Usel
for lower case letter from a to z
UseL
for upper case letter from A to Z
Used
for digit from 0 to 9
Usep
for punctuation
Usec
for custom character
!
,"
,#
,$
,%
,&
,'
,(
,)
,*
,+
,,
,-
,.
,/
,:
,;
,<
,=
,>
,?
,@
,[
,\
,]
,^
,_
,{
,|
,}
,~
and`
iex>RandomStringGenerator.generate("lldd")"ol68"
iex>RandomStringGenerator.generate("LL")"VR"
iex>RandomStringGenerator.generate("pp")"?!"
Delimiters
Everything that is notl
,L
,d
,p
andc
is treated as a delimiter sothe pattern-dl?
is interpreted as a hyphen followed by a digit followed bya lower case letter followed by a question mark.
iex>RandomStringGenerator.generate("ll-")"yz-"
Scape
In order to generate a string containing the charactersl
,L
,d
andp
as a delimiter, you need to use the backslash twice in order to scape it.
iex>RandomStringGenerator.generate("dd\\l\\L\\d\\p")"39lLdp"
Custom Chars
I order to generate a string based on a given custom patternccc
a listof possible values need to be passed as an argument.
iex>RandomStringGenerator.generate("ccc",["+","-","/","*"])"+/*"
If no custom char list is passed the with characterc
it will be treatedas adelimiter as in the example below where it generates a string containingone digit followed by the letter c followed by another digit
iex>RandomStringGenerator.generate("dcd")"2c1"
Shuffling
In order to generate a string based on a given patterLldd
where thosecharacters are placed in a random order, theshuffle/1
function shouldbe used.
iex>RandomStringGenerator.generate("Lldd")|>RandomStringGenerator.shuffle()"s22E"
Full documentation athttps://hexdocs.pm/random_string_generator.
About
A Elixir module to generate a random string based on a given string pattern.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.