I have a similar situation and my choice was $unique = int rand 1000000000 Not guaranteed 100% unique, but I'm prepared to bet on it. The more zeroes, the closer to true uniqueness! n.b. I'm pretty much making this up as I go, so this is almost certainly not the canonical solution: but it has the merits that it is simple and one knows how it works.