generate_id

Function generate_id 

Source
pub fn generate_id() -> u64
Expand description

Generate a new id

This function generates a new key using the following algorithm:

  1. Generate a random 16-bit number
  2. Generate a 48-bit number representing the number of milliseconds since the Kleio Epoch
  3. 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.