469,322 Members | 1,559 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

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 2157
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Nel | last post: by
2 posts views Thread by Simon Wittber | last post: by
9 posts views Thread by Robert Mago | last post: by
8 posts views Thread by Marc | last post: by
14 posts views Thread by Steven D'Aprano | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.