[erlang-questions] Password generator in Erlang

Loïc Hoguin essen@REDACTED
Tue Aug 14 17:40:45 CEST 2012


os:cmd("pwgen | cut -c 1-8").

On 08/14/2012 05:35 PM, Zabrane Mickael wrote:
> Hi guys,
>
> This one fires a lot of collisions
> (http://schemecookbook.org/Erlang/NumberRandomNumber):
>
> ------------------
> test() ->
>      crypto:start(),
>      N = 10000,
>      io:format("Generate ~p random passwords and check for collisions
> ...~n", [N]),
>      test(N, dict:new(), 0).
> test(0, _, C) ->
>      io:format("Number of collisions: ~p~n", [C]);
> test(N, Dict, C) ->
>      Password = passwd(),
>      case dict:find(Password, Dict) of
>          {ok, _} -> %% collision detected
>              test(N - 1, Dict, C + 1);
>          error ->
>              test(N - 1, dict:append(Password, 1, Dict), C)
>      end.
>
> passwd() ->
>      passwd(8).
> passwd(Length) ->
>      {A1,A2,A3} = now(),
>      random:seed(A1, A2, A3),
>      lists:flatten(lists:foldl(fun(_,AccIn) ->
>                                        [random:uniform(90) + 32 | AccIn]
> end,
>                                [], lists:seq(1,Length))).
>
> ----------------
>
>  > passwd:test().
> Generate 10000 random password and check for collisions ...
> Number of collisions: 1182
>
> Anything better guys? Something with less collisions if possible.
>
> Regards,
> Zabrane
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>


-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu



More information about the erlang-questions mailing list