Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. generate random number [modified]

generate random number [modified]

Scheduled Pinned Locked Moved Visual Basic
performancetutorialquestionlounge
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marc Soleda
    wrote on last edited by
    #1

    Hi all, In Vb2005, I need to develop a program that sends alphanumeric sequences to a device. These sequences have to be random and must not repeat any previous one done during the same day. I cannot store the used sequences, neither in disk nor in memory. Any idea on how to do that? thanks in advance, Marc Soleda

    ... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits

    D J 2 Replies Last reply
    0
    • M Marc Soleda

      Hi all, In Vb2005, I need to develop a program that sends alphanumeric sequences to a device. These sequences have to be random and must not repeat any previous one done during the same day. I cannot store the used sequences, neither in disk nor in memory. Any idea on how to do that? thanks in advance, Marc Soleda

      ... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You haven't said anything describing these "random sequences". How long are they? Variable length? What are the legal characters? Any illegal characters? Does if have to be in a certain format? Can the sequences be patially similar to previous ones in the same day? (Like "these" and "this") You're going to have to "remember" the sequences somewhere to make sure that you don't use the same one twice. "Random" doesn't mean "unique" acrossed the set of available numbers.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You haven't said anything describing these "random sequences". How long are they? Variable length? What are the legal characters? Any illegal characters? Does if have to be in a certain format? Can the sequences be patially similar to previous ones in the same day? (Like "these" and "this") You're going to have to "remember" the sequences somewhere to make sure that you don't use the same one twice. "Random" doesn't mean "unique" acrossed the set of available numbers.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        M Offline
        M Offline
        Marc Soleda
        wrote on last edited by
        #3

        Hi Dave, these random sequences have to be 6 digits long and composed using 0 to 9 and A to Z characters. The intention was to make an alphanumerical counter but we want something more elaborated that seems a random number. I was thinking to use an encrption algorithm where the string to encrypt shoud be the counter. By this way I shouldn't have to store the strings already done and I just have to store the actual counter value. Thanks, Marc Soleda

        ... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits

        D 1 Reply Last reply
        0
        • M Marc Soleda

          Hi Dave, these random sequences have to be 6 digits long and composed using 0 to 9 and A to Z characters. The intention was to make an alphanumerical counter but we want something more elaborated that seems a random number. I was thinking to use an encrption algorithm where the string to encrypt shoud be the counter. By this way I shouldn't have to store the strings already done and I just have to store the actual counter value. Thanks, Marc Soleda

          ... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You could do this, but ANY RNG can generate the same sequence of characters somewhere down the line, however unlikely it may seem. RNGCryptoServiceProvider Class[^].

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          M 1 Reply Last reply
          0
          • M Marc Soleda

            Hi all, In Vb2005, I need to develop a program that sends alphanumeric sequences to a device. These sequences have to be random and must not repeat any previous one done during the same day. I cannot store the used sequences, neither in disk nor in memory. Any idea on how to do that? thanks in advance, Marc Soleda

            ... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits

            J Offline
            J Offline
            Johan Hakkesteegt
            wrote on last edited by
            #5

            Hi Marc, The first thing that comes to mind is to make use of Now(). Whenever you call it, it will give you a different value, and it will never ever repeat. You could for example use its .Hour, .Minute and .Second parts, and replace leading zeros with a random letter from A to Z. Alternatively each datetime is a number as far as the computer is concerned, and will also nerver ever repeat, so you could use that in some sort of algorithm or formula. Johan

            My advice is free, and you may get what you paid for.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              You could do this, but ANY RNG can generate the same sequence of characters somewhere down the line, however unlikely it may seem. RNGCryptoServiceProvider Class[^].

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              M Offline
              M Offline
              Marc Soleda
              wrote on last edited by
              #6

              Hi again, as I said I don't really need a random number, I just need a unique 6 digit number that it seems random, so, do you a encryption wrapper class that takes a 6 digit counter and encrypts it to a 6 digit alphanumeric string. That would do the job, but I don't know which one does it!! Thanks in advance, Marc Soleda

              ... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups