Posts

Showing posts with the label ID

JavaScript Pseudo-Random ID Generator

Simple Random Id Generator for JavaScript Sometimes you might need a Random ID generator. The following generator takes an integer from which it will generate a string of that length. Longer string means more permutations and increased uniqueness. The following function was tested with input 15. A sample space of 5,000,000 IDs was generated and all were tested unique. function generateRandomId ( length ) {     "use strict" ;     var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" , returnValue = "" , x , i ;     for ( x = 0 ; x < length ; x += 1 ) {         i = Math . floor ( Math . random () * 62 );         returnValue += chars . charAt ( i );     }     return "ID_" + returnValue ; } NB: Increase length for increased uniqueness GenerateRando...