Skip to content

Commit

Permalink
Better(?) random function for shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimDavid committed Feb 14, 2012
1 parent fe79b4e commit 78f9c83
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/deck.erl
Expand Up @@ -167,10 +167,7 @@ internal_shuffle() ->
#state{deck=ShuffledDecks,cards_left=SplitNr}.


random_list(List) ->
random_list(List) ->
random:seed(now()),
{NewList, _} = lists:foldl( fun(_El, {Acc,Rest}) ->
RandomEl = lists:nth( random:uniform(length(Rest)), Rest),
{[RandomEl|Acc], lists:delete(RandomEl, Rest)}
end, {[],List}, List),
NewList = [X||{_,X} <- lists:sort([ {random:uniform(), N} || N <- List])],
NewList.

0 comments on commit 78f9c83

Please sign in to comment.