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. C#
  4. Generating random number of fixed-size

Generating random number of fixed-size

Scheduled Pinned Locked Moved C#
csharplounge
7 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.
  • G Offline
    G Offline
    Gerry
    wrote on last edited by
    #1

    Hi, I want to generate a random number of fixed-size for passwords. The size of the password must be 8 digits. I'm using c#, .net 1.1 Cheers Gerry.

    N N 2 Replies Last reply
    0
    • G Gerry

      Hi, I want to generate a random number of fixed-size for passwords. The size of the password must be 8 digits. I'm using c#, .net 1.1 Cheers Gerry.

      N Offline
      N Offline
      Nnamdi Onyeyiri
      wrote on last edited by
      #2

      Random rand = new Random();
      string pwd = rand.Next(10000000, 99999999).ToString();

      that should do the trick.

      | Website: http://www.onyeyiri.co.uk | Sonork: 100.21142 : TheEclypse | "If a dolar was a chicken would the chicken be evil?"

      N 1 Reply Last reply
      0
      • G Gerry

        Hi, I want to generate a random number of fixed-size for passwords. The size of the password must be 8 digits. I'm using c#, .net 1.1 Cheers Gerry.

        N Offline
        N Offline
        Nick Seng
        wrote on last edited by
        #3

        Create an int array of size 8, and assign a random number(range 0 to 9) for each int. Notorious SMC


        The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
        Get your facts first, and then you can distort them as much as you please Mark Twain

        G 1 Reply Last reply
        0
        • N Nnamdi Onyeyiri

          Random rand = new Random();
          string pwd = rand.Next(10000000, 99999999).ToString();

          that should do the trick.

          | Website: http://www.onyeyiri.co.uk | Sonork: 100.21142 : TheEclypse | "If a dolar was a chicken would the chicken be evil?"

          N Offline
          N Offline
          Nick Seng
          wrote on last edited by
          #4

          DUH :-O I thought of doing that with int, but the size would be too large. So I thought of using an int array Should've thought of using string instead ::Incredibly embarrased:: Notorious SMC


          The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
          Get your facts first, and then you can distort them as much as you please Mark Twain

          N 1 Reply Last reply
          0
          • N Nick Seng

            DUH :-O I thought of doing that with int, but the size would be too large. So I thought of using an int array Should've thought of using string instead ::Incredibly embarrased:: Notorious SMC


            The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
            Get your facts first, and then you can distort them as much as you please Mark Twain

            N Offline
            N Offline
            Nnamdi Onyeyiri
            wrote on last edited by
            #5

            but the two parameters sent to Random.Next are int's, i checked the max value of int's just a minute ago using the Int32.MaxValue property, and it had more than 8 digits in it, i only converted it to string because it was a password.

            | Website: http://www.onyeyiri.co.uk | Sonork: 100.21142 : TheEclypse | "If a dolar was a chicken would the chicken be evil?"

            N 1 Reply Last reply
            0
            • N Nnamdi Onyeyiri

              but the two parameters sent to Random.Next are int's, i checked the max value of int's just a minute ago using the Int32.MaxValue property, and it had more than 8 digits in it, i only converted it to string because it was a password.

              | Website: http://www.onyeyiri.co.uk | Sonork: 100.21142 : TheEclypse | "If a dolar was a chicken would the chicken be evil?"

              N Offline
              N Offline
              Nick Seng
              wrote on last edited by
              #6

              I'm just embarassing myself more and more, aren't I? :-O For a minute there, I was using Int16 ?!?! Notorious SMC


              The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
              Get your facts first, and then you can distort them as much as you please Mark Twain

              1 Reply Last reply
              0
              • N Nick Seng

                Create an int array of size 8, and assign a random number(range 0 to 9) for each int. Notorious SMC


                The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
                Get your facts first, and then you can distort them as much as you please Mark Twain

                G Offline
                G Offline
                Gerry
                wrote on last edited by
                #7

                Thanks for replying. But this random number generator isn't as secure as cryptography RGN's. Something like the RandomNumberGenerator class. Cheers, Gerry. Gerry.

                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