Generating unique random numbers

Miles Sabin miles at milessabin.com
Wed Jun 15 10:38:05 EDT 2005


Robert van Herk wrote,
> Hello all,
>
> Is it possible to generate random numbers that are "unique"  in O(1)
> in Haskell?
>
> I mean something like the GUID-thingy Windows uses.
>
> Of course, I could create unique numbers by incrementing a global
> value, but for security reasons I need random numbers. Also, I could
> use a list of numbers already in use, but this would mean that I'd
> not be able to generate a new number in O(1).

There are standard algorithms for doing this job, and it might be better 
to use one of them rather than reinventing the wheel. See here,

  http://www.itu.int/ITU-T/asn1/uuid.html

or possibly here,

  http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-05.txt

Open source implementations in a variety of (imperative) languages and 
with a variety of licenses are available via google. There's also one 
in J2SE 5.0.

Cheers,


Miles


More information about the Glasgow-haskell-users mailing list