Web analytics sometimes requires generating visit ID or visitor ID for storing in the cookies. Below is the code to generate a short enough “unqie” ID for the purpose. It needs to be under 20 characters because Adobe SiteCatalyst / Omniture would only take 20 characters long serialization string. You can control the length by changing the parameter in the slice function.
I am planning to use it with the product code to form a unique serialization string. One thing needs to be clarified is that the string is random, but not really “unique”. However, it is close enough. The chance of having two same strings is pretty small if you keep the string length over 10 characters. Appending a timestamp to string would make it unique.