I needed a random string for various purposes. For example, to provide a unique ID to HTML elements via JavaScript. The code below is a semi-random string generator function.
var guid = function() { var S4 = function() { return (((1 + Math.random()) * 0x10000)|0).toString(16).substring(1); }; return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4()); };
Find more JavaScript tutorials, code snippets and samples here or more jQuery tutorials, code snippets and samples here.
Find more JavaScript tutorials, code snippets and samples here or more jQuery tutorials, code snippets and samples here.
Use SpeedFactor to track your website. It’s simple and reliable.
See how real people experience the speed of your website. Then find (and fix) your web performance problems.
Get Started