uniqueid
Generates unique id
How does it work
Internally, it uses a pseudoencrypt
function based on a similar name from the Postgre Wiki. This encryption (not hashing) function generates a unique 32bit signed integer from a given 32bit integer. Since the function is an encryption, we can also infer that the pseudoEncrypt(pseudoEncrypt(x)) = x;
.
Secondly, the resulting integer is used as a basis for generating a unique code. The integer is converted to the baseN sequence of characters constructed by the alphabet definition.
Users may define their own alphabet sequence, or their own sauce (a permutation formula being used inside pseudoencrypt
that produces a value between 0 and 1), to produce a completely different sequence of ids.
Usage
This package exports a default class named "UniqueIdGenerator". This class creates an instance for generating unique ids.
The constructor for UniqueIdGenerator may receive two parameters:

alphabet
 the base of character encryption. The default sequence isabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
. 
sauce
 a permutation formula used for thepseudoencrypt
algorithm. The default is((1366 * r1 + 150889) % 714025) / 714025.0)
wherer1
is a 16bit value.
Once an instance is constructed, the next
method can be used to generate a unique string. This method receives a number that is used by the pseudoencrypt
function.
Reference
 Stack Overflow: https://stackoverflow.com/a/12590064