This snippet defines a function returning new identifiers created from reading the computer's time.
Version 0.2.1 sorts ascii letters to generate ordered words (at least as long as generated words have 11 characters). This is particularly useful if this code is used to generate file names in a directory.
is there any particular reason for 11 characters?
No, it is due to the granularity of floating numbers on a 64 bits processor :)
@ddanbe I thought again about your question, and it occured to me that I was losing some granularity by converting a number of seconds since the epoch into a string. Indeed, the new function
perf_counter() in python can potentially measure very small fractions of a second.
So, version 0.3.0 implements a new strategy: the number of seconds since the beginning of the day is converted to an 11 characters string and a 3 characters prefix is prepended for the day, which means that the function can work until year 2354.
Theoretically, having more characters means that more unique names can be generated in a very short time. Of course this code is actually slow, because it is in pure python, but it could be a first step towards a fast compiled function to do this :)
Thank you for your support !
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.