Numbers Question!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vai2000

    #1

    Numbers Question!

    what's the best way of getting unique numbers when requested other than
    creating GUIDs? Right now this is what I am doing but I am not very happy
    with it.


    Random rnd=new Random((int)Sys tem.DateTime.No w.Ticks);
    int unique=rnd.Next ();

    TIA

    --
    ========
    Regards
    Vai
    ========


  • Gary van der Merwe

    #2
    Re: Numbers Question!

    Hi Vai

    What are these numbers for? Are they for records in a database? What is
    wrong with a Guid?

    Gary

    "Vai2000" <vai@onebox.com > wrote in message
    news:%23MeFd1Sk DHA.2772@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > what's the best way of getting unique numbers when requested other than
    > creating GUIDs? Right now this is what I am doing but I am not very happy
    > with it.
    >
    >
    > Random rnd=new Random((int)Sys tem.DateTime.No w.Ticks);
    > int unique=rnd.Next ();
    >
    > TIA
    >
    > --
    > ========
    > Regards
    > Vai
    > ========
    >
    >[/color]


    Comment

    • Hans Kesting

      #3
      Re: Numbers Question!


      "Vai2000" <vai@onebox.com > wrote in message
      news:%23MeFd1Sk DHA.2772@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > what's the best way of getting unique numbers when requested other than
      > creating GUIDs? Right now this is what I am doing but I am not very happy
      > with it.
      >
      >
      > Random rnd=new Random((int)Sys tem.DateTime.No w.Ticks);
      > int unique=rnd.Next ();
      >
      > TIA
      >
      > --
      > ========
      > Regards
      > Vai
      > ========
      >
      >[/color]

      Hi,

      A random number is NOT unique! It is unpredictable (that's what "random"
      means :-) ) but it is possible to get duplicate values.

      Hans Kesting


      Comment

      • Vai2000

        #4
        Re: Numbers Question!

        Unfortunately I need this value for creating unique numerical ID (Its part
        of a naming convention) - I don't have access to DB!!

        Thanks


        "Gary van der Merwe" <garyvdm@hotmai l.com> wrote in message
        news:ubg1CbVkDH A.2772@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Hi Vai
        >
        > What are these numbers for? Are they for records in a database? What is
        > wrong with a Guid?
        >
        > Gary
        >
        > "Vai2000" <vai@onebox.com > wrote in message
        > news:%23MeFd1Sk DHA.2772@TK2MSF TNGP10.phx.gbl. ..[color=green]
        > > what's the best way of getting unique numbers when requested other than
        > > creating GUIDs? Right now this is what I am doing but I am not very[/color][/color]
        happy[color=blue][color=green]
        > > with it.
        > >
        > >
        > > Random rnd=new Random((int)Sys tem.DateTime.No w.Ticks);
        > > int unique=rnd.Next ();
        > >
        > > TIA
        > >
        > > --
        > > ========
        > > Regards
        > > Vai
        > > ========
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Gary van der Merwe

          #5
          Re: Numbers Question!

          Do you have any way of determining the names allready created?



          "Vai2000" <nospam@microso ft.com> wrote in message
          news:ulpUfzYkDH A.2592@TK2MSFTN GP10.phx.gbl...[color=blue]
          > Unfortunately I need this value for creating unique numerical ID (Its part
          > of a naming convention) - I don't have access to DB!!
          >
          > Thanks
          >
          >
          > "Gary van der Merwe" <garyvdm@hotmai l.com> wrote in message
          > news:ubg1CbVkDH A.2772@TK2MSFTN GP12.phx.gbl...[color=green]
          > > Hi Vai
          > >
          > > What are these numbers for? Are they for records in a database? What is
          > > wrong with a Guid?
          > >
          > > Gary
          > >
          > > "Vai2000" <vai@onebox.com > wrote in message
          > > news:%23MeFd1Sk DHA.2772@TK2MSF TNGP10.phx.gbl. ..[color=darkred]
          > > > what's the best way of getting unique numbers when requested other[/color][/color][/color]
          than[color=blue][color=green][color=darkred]
          > > > creating GUIDs? Right now this is what I am doing but I am not very[/color][/color]
          > happy[color=green][color=darkred]
          > > > with it.
          > > >
          > > >
          > > > Random rnd=new Random((int)Sys tem.DateTime.No w.Ticks);
          > > > int unique=rnd.Next ();
          > > >
          > > > TIA
          > > >
          > > > --
          > > > ========
          > > > Regards
          > > > Vai
          > > > ========
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Chris R. Timmons

            #6
            Re: Numbers Question!

            "Vai2000" <vai@onebox.com > wrote in
            news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
            [color=blue]
            > what's the best way of getting unique numbers when requested
            > other than creating GUIDs?[/color]

            Use a linear series: 1, 2, 3, etc...


            Chris.
            -------------
            C.R. Timmons Consulting, Inc.

            Comment

            • Vai2000

              #7
              Re: Numbers Question!

              No
              "Gary van der Merwe" <garyvdm@hotmai l.com> wrote in message
              news:%23cBQtKZk DHA.976@tk2msft ngp13.phx.gbl.. .[color=blue]
              > Do you have any way of determining the names allready created?
              >
              >
              >
              > "Vai2000" <nospam@microso ft.com> wrote in message
              > news:ulpUfzYkDH A.2592@TK2MSFTN GP10.phx.gbl...[color=green]
              > > Unfortunately I need this value for creating unique numerical ID (Its[/color][/color]
              part[color=blue][color=green]
              > > of a naming convention) - I don't have access to DB!!
              > >
              > > Thanks
              > >
              > >
              > > "Gary van der Merwe" <garyvdm@hotmai l.com> wrote in message
              > > news:ubg1CbVkDH A.2772@TK2MSFTN GP12.phx.gbl...[color=darkred]
              > > > Hi Vai
              > > >
              > > > What are these numbers for? Are they for records in a database? What[/color][/color][/color]
              is[color=blue][color=green][color=darkred]
              > > > wrong with a Guid?
              > > >
              > > > Gary
              > > >
              > > > "Vai2000" <vai@onebox.com > wrote in message
              > > > news:%23MeFd1Sk DHA.2772@TK2MSF TNGP10.phx.gbl. ..
              > > > > what's the best way of getting unique numbers when requested other[/color][/color]
              > than[color=green][color=darkred]
              > > > > creating GUIDs? Right now this is what I am doing but I am not very[/color]
              > > happy[color=darkred]
              > > > > with it.
              > > > >
              > > > >
              > > > > Random rnd=new Random((int)Sys tem.DateTime.No w.Ticks);
              > > > > int unique=rnd.Next ();
              > > > >
              > > > > TIA
              > > > >
              > > > > --
              > > > > ========
              > > > > Regards
              > > > > Vai
              > > > > ========
              > > > >
              > > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Vai2000

                #8
                Re: Numbers Question!

                Could you please elaborate a little more? basically I don't have any
                knowledge of my last number, so how can I ensure a linear number?

                Thanks
                PS: Ways I can think would be registry etc to maintain a starting seed and
                then increment it everytime.

                "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in message
                news:Xns94136D7 A6A842crtimmons crtimmonsin@207 .46.248.16...[color=blue]
                > "Vai2000" <vai@onebox.com > wrote in
                > news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
                >[color=green]
                > > what's the best way of getting unique numbers when requested
                > > other than creating GUIDs?[/color]
                >
                > Use a linear series: 1, 2, 3, etc...
                >
                >
                > Chris.
                > -------------
                > C.R. Timmons Consulting, Inc.
                > http://www.crtimmonsinc.com/[/color]


                Comment

                • Chris R. Timmons

                  #9
                  Re: Numbers Question!

                  "Vai2000" <nospam@microso ft.com> wrote in
                  news:ue23ynckDH A.1884@TK2MSFTN GP09.phx.gbl:
                  [color=blue]
                  > Could you please elaborate a little more? basically I don't have
                  > any knowledge of my last number, so how can I ensure a linear
                  > number?
                  >
                  > Thanks
                  > PS: Ways I can think would be registry etc to maintain a
                  > starting seed and then increment it everytime.[/color]

                  If you can somehow save (or find out) the value of the last number
                  used in the series, then it should be simple:

                  number is requested
                  get value of most recently used number (from a data store)
                  increment number
                  store new number value in the data store
                  return number

                  Multi-user and multi-threaded access should be planned for. The
                  above pseudo-code should be be "locked" somehow so only one
                  thread/user can access it at a time. With threads, the "lock"
                  statement can be used. With databases, the code can be wrapped in a
                  transaction, or the isolation level can be set to serial access.


                  Chris.
                  -------------
                  C.R. Timmons Consulting, Inc.

                  Comment

                  • Doug Forster

                    #10
                    Re: Numbers Question!

                    You still haven't answered Garys original question. Whats wrong with a Guid
                    ? This is the most reliable and easy way of generating a unique (to all
                    practical purposes) number on any computer without a complex error prone
                    tracking system.

                    Cheers

                    Doug Forster

                    "Vai2000" <nospam@microso ft.com> wrote in message
                    news:ue23ynckDH A.1884@TK2MSFTN GP09.phx.gbl...[color=blue]
                    > Could you please elaborate a little more? basically I don't have any
                    > knowledge of my last number, so how can I ensure a linear number?
                    >
                    > Thanks
                    > PS: Ways I can think would be registry etc to maintain a starting seed and
                    > then increment it everytime.
                    >
                    > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in message
                    > news:Xns94136D7 A6A842crtimmons crtimmonsin@207 .46.248.16...[color=green]
                    > > "Vai2000" <vai@onebox.com > wrote in
                    > > news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
                    > >[color=darkred]
                    > > > what's the best way of getting unique numbers when requested
                    > > > other than creating GUIDs?[/color]
                    > >
                    > > Use a linear series: 1, 2, 3, etc...
                    > >
                    > >
                    > > Chris.
                    > > -------------
                    > > C.R. Timmons Consulting, Inc.
                    > > http://www.crtimmonsinc.com/[/color]
                    >
                    >[/color]


                    Comment

                    • Vai2000

                      #11
                      Re: Numbers Question!

                      Well I need a number as to a GUID which is a combination of number and
                      alphabets!

                      TIA

                      "Doug Forster" <doug_ZAPTHIS_A T_TONIQ_ZAPTHIS _co.nz> wrote in message
                      news:uwGY1yfkDH A.1708@TK2MSFTN GP12.phx.gbl...[color=blue]
                      > You still haven't answered Garys original question. Whats wrong with a[/color]
                      Guid[color=blue]
                      > ? This is the most reliable and easy way of generating a unique (to all
                      > practical purposes) number on any computer without a complex error prone
                      > tracking system.
                      >
                      > Cheers
                      >
                      > Doug Forster
                      >
                      > "Vai2000" <nospam@microso ft.com> wrote in message
                      > news:ue23ynckDH A.1884@TK2MSFTN GP09.phx.gbl...[color=green]
                      > > Could you please elaborate a little more? basically I don't have any
                      > > knowledge of my last number, so how can I ensure a linear number?
                      > >
                      > > Thanks
                      > > PS: Ways I can think would be registry etc to maintain a starting seed[/color][/color]
                      and[color=blue][color=green]
                      > > then increment it everytime.
                      > >
                      > > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in[/color][/color]
                      message[color=blue][color=green]
                      > > news:Xns94136D7 A6A842crtimmons crtimmonsin@207 .46.248.16...[color=darkred]
                      > > > "Vai2000" <vai@onebox.com > wrote in
                      > > > news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
                      > > >
                      > > > > what's the best way of getting unique numbers when requested
                      > > > > other than creating GUIDs?
                      > > >
                      > > > Use a linear series: 1, 2, 3, etc...
                      > > >
                      > > >
                      > > > Chris.
                      > > > -------------
                      > > > C.R. Timmons Consulting, Inc.
                      > > > http://www.crtimmonsinc.com/[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Doug Forster

                        #12
                        Re: Numbers Question!

                        No a Guid is really a 16 byte number. You are thinking of the common hex
                        representation of a Guid. Use ToByteArray() and then you can represent it
                        however you like. Perhaps you could even 'condense' it at the risk of
                        reducing uniqueness.

                        Cheers

                        Doug Forster

                        "Vai2000" <vai@onebox.com > wrote in message
                        news:u7Pi2KgkDH A.2200@TK2MSFTN GP12.phx.gbl...[color=blue]
                        > Well I need a number as to a GUID which is a combination of number and
                        > alphabets!
                        >
                        > TIA
                        >
                        > "Doug Forster" <doug_ZAPTHIS_A T_TONIQ_ZAPTHIS _co.nz> wrote in message
                        > news:uwGY1yfkDH A.1708@TK2MSFTN GP12.phx.gbl...[color=green]
                        > > You still haven't answered Garys original question. Whats wrong with a[/color]
                        > Guid[color=green]
                        > > ? This is the most reliable and easy way of generating a unique (to all
                        > > practical purposes) number on any computer without a complex error prone
                        > > tracking system.
                        > >
                        > > Cheers
                        > >
                        > > Doug Forster
                        > >
                        > > "Vai2000" <nospam@microso ft.com> wrote in message
                        > > news:ue23ynckDH A.1884@TK2MSFTN GP09.phx.gbl...[color=darkred]
                        > > > Could you please elaborate a little more? basically I don't have any
                        > > > knowledge of my last number, so how can I ensure a linear number?
                        > > >
                        > > > Thanks
                        > > > PS: Ways I can think would be registry etc to maintain a starting seed[/color][/color]
                        > and[color=green][color=darkred]
                        > > > then increment it everytime.
                        > > >
                        > > > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in[/color][/color]
                        > message[color=green][color=darkred]
                        > > > news:Xns94136D7 A6A842crtimmons crtimmonsin@207 .46.248.16...
                        > > > > "Vai2000" <vai@onebox.com > wrote in
                        > > > > news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
                        > > > >
                        > > > > > what's the best way of getting unique numbers when requested
                        > > > > > other than creating GUIDs?
                        > > > >
                        > > > > Use a linear series: 1, 2, 3, etc...
                        > > > >
                        > > > >
                        > > > > Chris.
                        > > > > -------------
                        > > > > C.R. Timmons Consulting, Inc.
                        > > > > http://www.crtimmonsinc.com/
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Vai2000

                          #13
                          Re: Numbers Question!

                          Great!!
                          "Doug Forster" <doug_ZAPTHIS_A T_TONIQ_ZAPTHIS _co.nz> wrote in message
                          news:%23N6L9jgk DHA.1004@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                          > No a Guid is really a 16 byte number. You are thinking of the common hex
                          > representation of a Guid. Use ToByteArray() and then you can represent it
                          > however you like. Perhaps you could even 'condense' it at the risk of
                          > reducing uniqueness.
                          >
                          > Cheers
                          >
                          > Doug Forster
                          >
                          > "Vai2000" <vai@onebox.com > wrote in message
                          > news:u7Pi2KgkDH A.2200@TK2MSFTN GP12.phx.gbl...[color=green]
                          > > Well I need a number as to a GUID which is a combination of number and
                          > > alphabets!
                          > >
                          > > TIA
                          > >
                          > > "Doug Forster" <doug_ZAPTHIS_A T_TONIQ_ZAPTHIS _co.nz> wrote in message
                          > > news:uwGY1yfkDH A.1708@TK2MSFTN GP12.phx.gbl...[color=darkred]
                          > > > You still haven't answered Garys original question. Whats wrong with a[/color]
                          > > Guid[color=darkred]
                          > > > ? This is the most reliable and easy way of generating a unique (to[/color][/color][/color]
                          all[color=blue][color=green][color=darkred]
                          > > > practical purposes) number on any computer without a complex error[/color][/color][/color]
                          prone[color=blue][color=green][color=darkred]
                          > > > tracking system.
                          > > >
                          > > > Cheers
                          > > >
                          > > > Doug Forster
                          > > >
                          > > > "Vai2000" <nospam@microso ft.com> wrote in message
                          > > > news:ue23ynckDH A.1884@TK2MSFTN GP09.phx.gbl...
                          > > > > Could you please elaborate a little more? basically I don't have any
                          > > > > knowledge of my last number, so how can I ensure a linear number?
                          > > > >
                          > > > > Thanks
                          > > > > PS: Ways I can think would be registry etc to maintain a starting[/color][/color][/color]
                          seed[color=blue][color=green]
                          > > and[color=darkred]
                          > > > > then increment it everytime.
                          > > > >
                          > > > > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in[/color]
                          > > message[color=darkred]
                          > > > > news:Xns94136D7 A6A842crtimmons crtimmonsin@207 .46.248.16...
                          > > > > > "Vai2000" <vai@onebox.com > wrote in
                          > > > > > news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
                          > > > > >
                          > > > > > > what's the best way of getting unique numbers when requested
                          > > > > > > other than creating GUIDs?
                          > > > > >
                          > > > > > Use a linear series: 1, 2, 3, etc...
                          > > > > >
                          > > > > >
                          > > > > > Chris.
                          > > > > > -------------
                          > > > > > C.R. Timmons Consulting, Inc.
                          > > > > > http://www.crtimmonsinc.com/
                          > > > >
                          > > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Jason Smith

                            #14
                            Re: Numbers Question!

                            You can also use a SecureRandom to generate better random numbers. Decide
                            how often you are willing to have numbers collide, on average, and take
                            enough bits to ensure this.

                            If you aren't willing to have any collisions ever, you need to add a check
                            for uniqueness.

                            "Doug Forster" <doug_ZAPTHIS_A T_TONIQ_ZAPTHIS _co.nz> wrote in message
                            news:%23N6L9jgk DHA.1004@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                            > No a Guid is really a 16 byte number. You are thinking of the common hex
                            > representation of a Guid. Use ToByteArray() and then you can represent it
                            > however you like. Perhaps you could even 'condense' it at the risk of
                            > reducing uniqueness.
                            >
                            > Cheers
                            >
                            > Doug Forster
                            >
                            > "Vai2000" <vai@onebox.com > wrote in message
                            > news:u7Pi2KgkDH A.2200@TK2MSFTN GP12.phx.gbl...[color=green]
                            > > Well I need a number as to a GUID which is a combination of number and
                            > > alphabets!
                            > >
                            > > TIA
                            > >
                            > > "Doug Forster" <doug_ZAPTHIS_A T_TONIQ_ZAPTHIS _co.nz> wrote in message
                            > > news:uwGY1yfkDH A.1708@TK2MSFTN GP12.phx.gbl...[color=darkred]
                            > > > You still haven't answered Garys original question. Whats wrong with a[/color]
                            > > Guid[color=darkred]
                            > > > ? This is the most reliable and easy way of generating a unique (to[/color][/color][/color]
                            all[color=blue][color=green][color=darkred]
                            > > > practical purposes) number on any computer without a complex error[/color][/color][/color]
                            prone[color=blue][color=green][color=darkred]
                            > > > tracking system.
                            > > >
                            > > > Cheers
                            > > >
                            > > > Doug Forster
                            > > >
                            > > > "Vai2000" <nospam@microso ft.com> wrote in message
                            > > > news:ue23ynckDH A.1884@TK2MSFTN GP09.phx.gbl...
                            > > > > Could you please elaborate a little more? basically I don't have any
                            > > > > knowledge of my last number, so how can I ensure a linear number?
                            > > > >
                            > > > > Thanks
                            > > > > PS: Ways I can think would be registry etc to maintain a starting[/color][/color][/color]
                            seed[color=blue][color=green]
                            > > and[color=darkred]
                            > > > > then increment it everytime.
                            > > > >
                            > > > > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in[/color]
                            > > message[color=darkred]
                            > > > > news:Xns94136D7 A6A842crtimmons crtimmonsin@207 .46.248.16...
                            > > > > > "Vai2000" <vai@onebox.com > wrote in
                            > > > > > news:#MeFd1SkDH A.2772@TK2MSFTN GP10.phx.gbl:
                            > > > > >
                            > > > > > > what's the best way of getting unique numbers when requested
                            > > > > > > other than creating GUIDs?
                            > > > > >
                            > > > > > Use a linear series: 1, 2, 3, etc...
                            > > > > >
                            > > > > >
                            > > > > > Chris.
                            > > > > > -------------
                            > > > > > C.R. Timmons Consulting, Inc.
                            > > > > > http://www.crtimmonsinc.com/
                            > > > >
                            > > > >
                            > > >
                            > > >[/color]
                            > >
                            > >[/color]
                            >
                            >[/color]


                            Comment

                            Working...