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

Björn-Egil Dahlberg egil@REDACTED
Wed May 26 19:40:39 CEST 2010


On 2010-05-26 18:58, Jesper Louis Andersen wrote:
> 2010/5/26 Björn-Egil Dahlberg<egil@REDACTED>:
>> 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.

I like it. Etorrents version is almost like my suggestion, same idea 
anyway. However, the code i submitted is ~10+ times faster.

// Björn-Egil



More information about the erlang-questions mailing list