I'm using the following 2 lines of JS to create a UID:
var UID = dateobj.getTime();
UID = String(UID).substr(4);
It appears that sometimes it generates a number like:
564929300
other times like:
56492930
Problem is the length isn't consistent which is messing things up. Any ideas how that's possible and if there is a way to fix this or a better way to make a UID with JS?
Thanks
I'm using the following 2 lines of JS to create a UID:
var UID = dateobj.getTime();
UID = String(UID).substr(4);
It appears that sometimes it generates a number like:
564929300
other times like:
56492930
Problem is the length isn't consistent which is messing things up. Any ideas how that's possible and if there is a way to fix this or a better way to make a UID with JS?
Thanks
Share Improve this question edited Jul 13, 2010 at 23:27 Yacoby 55.5k16 gold badges117 silver badges121 bronze badges asked Jul 13, 2010 at 23:26 AnApprenticeAnApprentice 111k202 gold badges637 silver badges1k bronze badges 1- what date range are you dealing with? – meder omuraliev Commented Jul 13, 2010 at 23:30
2 Answers
Reset to default 8I like doing Math.random().toString(36).substr(2,9)
There one implementation here: http://blog.shkedy./2007/01/createing-guids-with-client-side.html
Here it is in action: http://jsfiddle/7sXL6/
I threw together a smaller version of it: http://jsfiddle/7sXL6/4/