pub fn generate_id() -> u64Expand description
Generate a new id
This function generates a new key using the following algorithm:
- Generate a random 16-bit number
- Generate a 48-bit number representing the number of milliseconds since the Kleio Epoch
- Combine the two numbers into a 64-bit number
This guarantees that the key is unique, granted there are no collisions in the random number generation at time x. There is a 50% possiblity of a collision if 110000 keys are generated at the same millisecond, assuming a uniform distribution of random numbers.
For any reasonable number of keys generated, the probability of a collision is negligible.