I need to be able to generate random url safe strings so I could use those in links (like in an activation link sent to a user\'s email), so how can I generate it? Is there a wa
You can easily define a module to do this. In this example, @chars
determines what characters appear in your generated strings.
defmodule StringGenerator do
@chars "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |> String.split("")
def string_of_length(length) do
Enum.reduce((1..length), [], fn (_i, acc) ->
[Enum.random(@chars) | acc]
end) |> Enum.join("")
end
end
StringGenerator.string_of_length(3) # => "YCZ"