Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create a K-Sortable Unique Identifiers hexadecimal string
ResourceFunction["CreateSortableUniqueID"][] retrieves a hexadecimal unique partial sortable ID string. | |
ResourceFunction["CreateSortableUniqueID"][n] retrieves a list of n hexadecimal unique partial sortable ID strings. |
Get one unique KSUID:
In[1]:= | ![]() |
Out[1]= | ![]() |
Get a list of unique IDs:
In[2]:= | ![]() |
Out[2]= | ![]() |
The beginning of a set of IDs are close to one another because they are based on Unix timestamps, while the second parts are pseudorandom hex digits:
In[3]:= | ![]() |
Out[3]= | ![]() |
We can check when a set of IDs were created:
In[4]:= | ![]() |
Take the first eight hexadecimal digits, converting to decimal and converting from Unix time format:
In[5]:= | ![]() |
Out[5]= | ![]() |
It is possible to recover the timestamp from an ID, step by step:
In[6]:= | ![]() |
Out[6]= | ![]() |
Take just the 8 initial characters:
In[7]:= | ![]() |
Out[7]= | ![]() |
Convert the hexadecimal to integer:
In[8]:= | ![]() |
Out[8]= | ![]() |
Convert from Unix time format:
In[9]:= | ![]() |
Out[9]= | ![]() |
Compare with the value of a current Unix time:
In[10]:= | ![]() |
Out[10]= | ![]() |
Validate the timestamp at the beginning of the hash:
In[11]:= | ![]() |
Out[11]= | ![]() |
Breaking the IDs into 2 hexadecimal pairs, we can plot the IDs as a graph, and view the random and repetitive parts:
In[12]:= | ![]() |
Out[12]= | ![]() |
We can view a set of IDs as an image:
In[13]:= | ![]() |
Out[13]= | ![]() |
We can likewise view a sorted set of IDs as an image:
In[14]:= | ![]() |
Out[14]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License