Skip to content

Commit 2e2f459

Browse files
committed
fix ai_ascii_random
1 parent 4899b40 commit 2e2f459

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/process/ai_ascii_random.erl

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323

2424
-define(SERVER, ?MODULE).
2525
-define(RAND,
26-
begin
27-
case code:ensure_loaded(rand) of
28-
{module, rand} -> rand;
29-
_ -> random
30-
end
31-
end).
26+
begin
27+
case code:ensure_loaded(rand) of
28+
{module, rand} -> rand;
29+
_ -> random
30+
end
31+
end).
3232
-define(SEED_STATE,
33-
begin
34-
case code:ensure_loaded(rand) of
35-
{module, rand} -> exs1024;
36-
_ -> erlang:system_time(micro_seconds)
37-
end
38-
end).
33+
begin
34+
case code:ensure_loaded(rand) of
35+
{module, rand} -> exs1024;
36+
_ -> erlang:system_time(microseconds)
37+
end
38+
end).
3939
-define(CHARS, "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890").
4040
-record(state,{chars}).
4141

4242
% @hidden
4343
start_link() ->
44-
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
44+
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
4545

4646
start_link(Args)->
47-
Type = proplists:get_value(register,Args),
48-
case Type of
49-
undefined -> gen_server:start_link(?MODULE,Args,[]);
50-
_ -> gen_server:start_link({Type, ?SERVER}, ?MODULE, [], [])
51-
end.
47+
Type = proplists:get_value(register,Args),
48+
case Type of
49+
undefined -> gen_server:start_link(?MODULE,Args,[]);
50+
_ -> gen_server:start_link({Type, ?SERVER}, ?MODULE, [], [])
51+
end.
5252

5353
randp(Pid,Length)->
5454
gen_server:call(Pid,{rand,Length}).
@@ -63,17 +63,17 @@ rand(Length, Allowed) -> randp(?SERVER,Length,Allowed).
6363

6464
% @hidden
6565
init(Args) ->
66-
Chars = proplists:get_value(chars,Args,?CHARS),
67-
_ = erlang:apply(?RAND, seed, [?SEED_STATE]),
68-
{ok, #state{chars = Chars}}.
66+
Chars = proplists:get_value(chars,Args,?CHARS),
67+
_ = erlang:apply(?RAND, seed, [?SEED_STATE]),
68+
{ok, #state{chars = Chars}}.
6969

7070
% @hidden
7171
handle_call({rand,Length},_From,#state{chars = Allowed} = State)->
72-
{reply, private_rand(Length, Allowed), State};
72+
{reply, private_rand(Length, Allowed), State};
7373
handle_call({rand, Length, Allowed}, _From, State) ->
74-
{reply, private_rand(Length, Allowed), State};
74+
{reply, private_rand(Length, Allowed), State};
7575
handle_call(_Request, _From, State) ->
76-
{reply, ok, State}.
76+
{reply, ok, State}.
7777

7878
% @hidden
7979
handle_cast(_Msg, State) -> {noreply, State}.
@@ -90,7 +90,6 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
9090
% Service implementation
9191

9292
private_rand(Size, Allowed) ->
93-
AllowedLength = length(Allowed),
94-
lists:flatten([lists:sublist(Allowed, erlang:apply(?RAND, uniform, [AllowedLength]), 1)
95-
|| _ <- lists:seq(1, Size)]).
96-
93+
AllowedLength = length(Allowed),
94+
lists:flatten([lists:sublist(Allowed, erlang:apply(?RAND, uniform, [AllowedLength]), 1)
95+
|| _ <- lists:seq(1, Size)]).

0 commit comments

Comments
 (0)