Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save pragmaticobjects/1263627 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),
map(R).
map(R) when R > 0, R < 11 ->
R - 1 + $0;
map(R) when R < 37 ->
R - 11 + $A;
map(R) ->
R - 37 + $a.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment