Generating unique random numbers

Miles Sabin miles at
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,

or possibly here,

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.



More information about the Glasgow-haskell-users mailing list