473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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

Similar topics

4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
4
by: RCS | last post by:
We have sort of a centralized single-signon written in ASP.NET for all of our legacy ASP and ASP.NET apps.. There are around 1200 users and something like 2 dozen apps. Everyonce in a while, a user...
3
by: Nel | last post by:
From your (group) opinion, when sending a unique URL to a user, what steps are a must in making sure the link can't be hacked. i.e. Bad link www.example.com?id=10&action=reset_password ...
5
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight...
2
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can...
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
8
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed....
14
by: Steven D'Aprano | last post by:
I have an application that will be producing many instances, using them for a while, then tossing them away, and I want each one to have a unique identifier that won't be re-used for the lifetime...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.