Skip to content

Commit

Permalink
Seed random number generator for each population
Browse files Browse the repository at this point in the history
  • Loading branch information
bzurkowski committed Mar 3, 2017
1 parent 4d370a9 commit f0f1767
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/mas_population.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_agents(Pid, Agents) ->
%% @private
%%------------------------------------------------------------------------------
init({SP, Config}) ->
mas_utils:seed_random(),
process_flag(trap_exit, true),
State = init_state(SP, Config),
schedule_metrics_update(Config),
Expand Down
13 changes: 12 additions & 1 deletion src/mas_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
sample/1,
index_of/2,
timestamp/0,
to_string/1]).
to_string/1,
seed_random/0]).

%%%=============================================================================
%%% API functions
Expand Down Expand Up @@ -70,6 +71,16 @@ to_string(X) when is_list(X) ->
to_string(X) ->
io_lib:format("~p", [X]).

%%------------------------------------------------------------------------------
%% @doc Seeds random number generator for current process.
%% @end
%%------------------------------------------------------------------------------
seed_random() ->
A1 = erlang:phash2([node()]),
A2 = erlang:monotonic_time(),
A3 = erlang:unique_integer(),
rand:seed(exs1024, {A1, A2, A3}).

%%%=============================================================================
%%% Internal functions
%%%=============================================================================
Expand Down

0 comments on commit f0f1767

Please sign in to comment.