471,881 Members | 1,397 Online

# giving a unique random number for user identification

The only way i know is either using combinations like
Expand|Select|Wrap|Line Numbers
1. var a=Math.round(Math.random()*1000000);
2. var b=Math.round(Math.random()*1000000);
3. var c=Math.round(new Date().getTime()/1000);
4.
5. d=a+""+b;
6. e=a+""+c;
7.
is there any other way to get a unique number with a very low probability of them being same
Sep 17 '07 #1
9 2201
gits
5,390 Expert Mod 4TB
hi ...

the following should always generate a unique value:

Expand|Select|Wrap|Line Numbers
1. var unique_val = + new Date;
kind regards
Sep 17 '07 #2
thanks gits

but its in my code
Expand|Select|Wrap|Line Numbers
1. var c=Math.round(new Date().getTime()/1000);
2.
Sep 17 '07 #3
gits
5,390 Expert Mod 4TB
not exactly as you can see :) ... you kill the last 3 positions with dividing by 1000 and round the result ... that gives the chance to be not unique when its called too fast ... try it ;)
Sep 17 '07 #4
i know it gives result in milliseconds

but i want a different type of random number that is not math.random or new date

is there any other type of random number
Sep 17 '07 #5
gits
5,390 Expert Mod 4TB
hmmm ... i don't know ... to be sure the timestamp is always unique ... even a random number might have a chance not to be unique ... but in case you want to have a 'pool' of numbers then you may create a list with numbers that you may assign to a user each time ... and assign that only once ...
Sep 17 '07 #6
thanks gits
ill try then combination of math.random and date object
i was checking if another type of random number exists
Sep 17 '07 #7
gits
5,390 Expert Mod 4TB
can you tell the purpose of this? it's better to assign a number at the server i think ... because it is (might be) security relevant? ...
Sep 17 '07 #8
nope it is nothing security relevant
i am using this for behavioral targeting
if i get a unique visitor number i might be able to track them
and with so many request on server engine i cant use it to set a unique number every time a visitor visit the websites as it will increase the load
Sep 17 '07 #9
gits
5,390 Expert Mod 4TB
i see ... so you assign the id to the user and track his behaviour with this id and may be he is getting proposals or special links or interfaces depending on his behaviour? :) ...

good luck with your project ... and post back to the forum anytime you have more questions,

kind regards
Sep 17 '07 #10