Skip to content

Instantly share code, notes, and snippets.

@pragmaticobjects
Created October 5, 2011 04:17
Show Gist options
  • Select an option

  • Save pragmaticobjects/1263620 to your computer and use it in GitHub Desktop.

Select an option

Save pragmaticobjects/1263620 to your computer and use it in GitHub Desktop.
Generate random passwords and/or ids
-module(random_password).
-export([make_random_password/1]).
make_random_password(N) ->
{A1,A2,A3} = now(),
random:seed(A1, A2, A3),
lists:map(fun(_) -> make_random_unfunny_char() end, lists:seq(1, N)).
make_random_unfunny_char() ->
R = random:uniform(62),
if
% 1 to 10
R > 0 andalso R < 11 -> R - 1 + $0;
% 11 to 36
R < 37 -> R - 11 + $A;
% 37 to 62
true -> R - 37 + $a
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment