Generating unique random numbers

Jens Fisseler jens.fisseler at
Tue Jun 14 10:52:15 EDT 2005

Hi Robert,

> 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).

do you really need random numbers? If not: I vaguely remember an
algorithm from one of the "Graphic Gems" books, implementing some sort
of fancy counter which goes through all numbers from 0,...,2^n-1 in a
seemingly random, but of course deterministic and repeatable order. It
was used for some sort of cross dissolve effect, because you can index
every pixel of a bitmap with one number (ignoring numbers mapped to
positions outside the screen/viewport/whatever) and this way blend from
one image to another.

If this sort of behavious suits your needs just let me know and I will
look it up.



More information about the Glasgow-haskell-users mailing list