Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Password generator in Erlang
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Zabrane Mickael  
View profile  
 More options Aug 14 2012, 12:12 pm
From: Zabrane Mickael <zabra...@gmail.com>
Date: Tue, 14 Aug 2012 18:12:14 +0200
Local: Tues, Aug 14 2012 12:12 pm
Subject: Re: [erlang-questions] Password generator in Erlang
Thank Serker.

Moving andom:seed(A1, A2, A3) at start fix it.

1> passwd:test().
Generate 10000 random password and check for collisions ...
Number of collisions: 0

--------------------
test() ->
    {A1,A2,A3} = now(),
    random:seed(A1, A2, A3),
    N = 10000,
    io:format("Generate ~p random password 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) ->

    lists:flatten(lists:foldl(fun(_,AccIn) ->
                                      [random:uniform(90) + 32 | AccIn] end,
                              [], lists:seq(1,Length))).

--------------------

Regards,
Zabrane

On Aug 14, 2012, at 5:43 PM, Sverker Eriksson wrote:

> Try only call random:seed(A1, A2, A3) once at start.

> For cryptographic safe random generation look at crypto module.

> /Sverker

> 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-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.