Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Use rand_uniform to fix deterministic zone placement
BugzID: 13486
  • Loading branch information
Robert Newson committed Apr 24, 2012
1 parent c8ca502 commit 72ef8be46f4476aea9051542041a26d59ee38d71
Showing 1 changed file with 4 additions and 13 deletions.
@@ -218,19 +218,10 @@ nodes_in_zone(Nodes, Zone) ->
[Node || Node <- Nodes, Zone == mem3:node_info(Node, <<"zone">>)].

shuffle(List) ->
%% Determine the log n portion then randomize the list.
randomize(round(math:log(length(List)) + 0.5), List).

randomize(1, List) ->
randomize(List);
randomize(T, List) ->
lists:foldl(fun(_E, Acc) -> randomize(Acc) end,
randomize(List), lists:seq(1, (T - 1))).

randomize(List) ->
D = lists:map(fun(A) -> {random:uniform(), A} end, List),
{_, D1} = lists:unzip(lists:keysort(1, D)),
D1.
List1 = [{crypto:rand_uniform(1, 1000), Item} || Item <- List],
List2 = lists:sort(List1),
{_, Result} = lists:unzip(List2),
Result.

apportion(Shares, Ways) ->
apportion(Shares, lists:duplicate(Ways, 0), Shares).

0 comments on commit 72ef8be

Please sign in to comment.