in reply to Ending up with duplicate keys in a hash?\

As said above...
$event_id = int(rand(25000));
is not guaranteed to produce unique event IDs.

I agree :)

You could use a function with locking that will increase a variable and return its value.