giving a unique random number for user identification

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rohitchawla
    New Member
    • Jul 2007
    • 85

    giving a unique random number for user identification

    The only way i know is either using combinations like
    [CODE=javascript]
    var a=Math.round(Ma th.random()*100 0000);
    var b=Math.round(Ma th.random()*100 0000);
    var c=Math.round(ne w Date().getTime( )/1000);

    d=a+""+b;
    e=a+""+c;
    [/CODE]

    is there any other way to get a unique number with a very low probability of them being same
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    the following should always generate a unique value:

    [CODE=javascript]var unique_val = + new Date;[/CODE]
    kind regards

    Comment

    • rohitchawla
      New Member
      • Jul 2007
      • 85

      #3
      thanks gits

      but its in my code
      [CODE=javascript]
      var c=Math.round(ne w Date().getTime( )/1000);
      [/CODE]

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        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 ;)

        Comment

        • rohitchawla
          New Member
          • Jul 2007
          • 85

          #5
          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

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            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 ...

            Comment

            • rohitchawla
              New Member
              • Jul 2007
              • 85

              #7
              thanks gits
              ill try then combination of math.random and date object
              i was checking if another type of random number exists

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                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? ...

                Comment

                • rohitchawla
                  New Member
                  • Jul 2007
                  • 85

                  #9
                  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

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    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

                    Comment

                    Working...