You assume it's the random selection that's at fault and not something like the database writes failing due to some lock or race condition, or any number of other myriad edge cases to stop the correctly chosen number being put into the database.