[erlang-questions] Speedy unsort:shuffle/1,2 ?

Jesper Louis Andersen <>
Wed May 26 18:58:15 CEST 2010


2010/5/26 Björn-Egil Dahlberg <>:
> I while back there were some talk about an unsort or shuffle operation for
> lists. I too was in need of this since it very convenient in testing, so I
> wrote one.

Etorrent has one in its utils library as well:

http://github.com/jlouis/etorrent/blob/master/src/etorrent_utils.erl#L101

It works by creating an analogy to shuffling a deck of cards and I am
somewhat sure it will uniformly shuffle (though I have not proved that
it is the case). The code is originally by Taylor Campbell if memory
serves. I also think this is an excellent candidate for a standard
library function. Getting it right is quite difficult. Getting it fast
and right is even more difficult. I also note that the
binary-generation trick ought to be usable on this one.

In Etorrent it is rarely called and every place where it is used, the
client would work even if you omit the call. Hence, it has not seen
much testing.


-- 
J.


More information about the erlang-questions mailing list