[erlang-questions] Speedy unsort:shuffle/1,2 ?
Håkan Huss
huss01@REDACTED
Fri May 28 08:42:53 CEST 2010
2010/5/28 Richard O'Keefe <ok@REDACTED>
>
> On May 28, 2010, at 1:12 AM, Björn-Egil Dahlberg wrote:
>
>> Is there no need for assigning unique numbers to the list when sorting it?
>> I guess it boils down to how fair we want the list to be unsorted (or how
>> one wants to word it).
>>
>
> If we really had something generating 53-bit random floats,
> the changes that a million-element list would get at least one
> duplicate would be
> 1 - (1 - 2**-53)**1,000,000
> or roughly 2**-33. Or put it another way: stop worrying. The
> RNG that Erlang uses has worse problems than that. It was
> great for its purpose in Quintus Prolog >25 years ago, but it
> has long since been surpassed.
>
Even though I used random:uniform/2 in the example I posted, any serious use
of random numbers should use the RNG functions in the crypto module instead.
For the "tag and sort", use crypto:rand_bytes/1 and you can choose how many
random bits you want the tag to have (and thus the probability of
collision). For instance, tagging with crypto:rand_bytes(7) will get you a
56 bit random binary with good quality.
Regards.
/Håkan
More information about the erlang-questions
mailing list