Random Reference Number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jacotheron
    New Member
    • Jan 2008
    • 44

    Random Reference Number

    I want to create a javascript that is able to randomly generate a 7 digit number and fill it in a textbox that is unchangeable. It should not repeat the same number before all of the possible numbers has already been used.

    Can someone please help??
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Unless you store all previous numbers, this won't be possible.

    Use Math.random() for the randomization. Note that it gives a number between 0 and 1. To get a useful number between 1 and something, use something like Math.floor(Math .random()*maxNu m+1).

    Comment

    • Jacotheron
      New Member
      • Jan 2008
      • 44

      #3
      Originally posted by acoder
      Unless you store all previous numbers, this won't be possible.

      Use Math.random() for the randomization. Note that it gives a number between 0 and 1. To get a useful number between 1 and something, use something like Math.floor(Math .random()*maxNu m+1).
      How would I store the previous numbers that it can't be used again in the next 30 days. With the "Math.floor(Mat h.random()*maxN um+1)" I supose I can get it right.

      Thank you for your help

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        hi ...

        in case you store it in a database you could retrieve all the used numbers on pageload and build a lookup list with it ... another way would be a cookie at the clientside ... but i would prefer the db-way :)

        kind regards

        Comment

        • Jacotheron
          New Member
          • Jan 2008
          • 44

          #5
          Originally posted by gits
          hi ...

          in case you store it in a database you could retrieve all the used numbers on pageload and build a lookup list with it ... another way would be a cookie at the clientside ... but i would prefer the db-way :)

          kind regards
          How do I create a database that the client browser can add the number automaticly. (I have very little experience in javascript as you might have noticed).

          Thanx for the help

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by Jacotheron
            How do I create a database that the client browser can add the number automaticly.
            A database would require server-side coding. Which language are you using on the server-side?

            Comment

            • Jacotheron
              New Member
              • Jan 2008
              • 44

              #7
              Originally posted by acoder
              A database would require server-side coding. Which language are you using on the server-side?
              I can't yet use any serverside code, but would try to do something about that (I am the same person of the "Bookings manager" and this client have selected the Micro option too, like every body else).

              I should have a reply about tomorrow (18 January 2008) about server side code.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by Jacotheron
                I can't yet use any serverside code, but would try to do something about that (I am the same person of the "Bookings manager" and this client have selected the Micro option too, like every body else).
                Yes, I noticed. You'll have to try to convince them. If they don't agree, you can use cookies, but that would only be random for that one person (not across al people using the system) and I think cookies have a size limit.

                Comment

                • Jacotheron
                  New Member
                  • Jan 2008
                  • 44

                  #9
                  Originally posted by acoder
                  Yes, I noticed. You'll have to try to convince them. If they don't agree, you can use cookies, but that would only be random for that one person (not across al people using the system) and I think cookies have a size limit.
                  Well, thanx for the help, even as I was not successful with this.

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by Jacotheron
                    Well, thanx for the help, even as I was not successful with this.
                    You weren't successful in convincing them that they needed server-side code? Sometimes clients need to know that things are simply not possible the way they see it. This can only be done on the server-side. JavaScript is great at what it does, but it's limited (for a reason).

                    Comment

                    Working...