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. How to generate a random number

How to generate a random number

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelptutoriallounge
5 Posts 4 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.
  • C Offline
    C Offline
    CodeItWell
    wrote on last edited by
    #1

    How to generate a random number. I have Visual Studio 2003. Help.

    Vasildb

    N 1 Reply Last reply
    0
    • C CodeItWell

      How to generate a random number. I have Visual Studio 2003. Help.

      Vasildb

      N Offline
      N Offline
      Neha_Gupta
      wrote on last edited by
      #2

      use the following code snippet: Random rand=new Random(); and then u can use rand.Next(1,100); to generate a random no. between 1 & 100 Basically u have to specify the limits in which u want to generate a random no. Hope this will work.:)

      NEHA GUPTA

      G 1 Reply Last reply
      0
      • N Neha_Gupta

        use the following code snippet: Random rand=new Random(); and then u can use rand.Next(1,100); to generate a random no. between 1 & 100 Basically u have to specify the limits in which u want to generate a random no. Hope this will work.:)

        NEHA GUPTA

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Neha_Gupta wrote:

        and then u can use rand.Next(1,100); to generate a random no. between 1 & 100

        That will generate a random number between 1 and 99.

        --- b { font-weight: normal; }

        N S 2 Replies Last reply
        0
        • G Guffa

          Neha_Gupta wrote:

          and then u can use rand.Next(1,100); to generate a random no. between 1 & 100

          That will generate a random number between 1 and 99.

          --- b { font-weight: normal; }

          N Offline
          N Offline
          Neha_Gupta
          wrote on last edited by
          #4

          Thanx Guffa for correcting me :)

          NEHA GUPTA

          1 Reply Last reply
          0
          • G Guffa

            Neha_Gupta wrote:

            and then u can use rand.Next(1,100); to generate a random no. between 1 & 100

            That will generate a random number between 1 and 99.

            --- b { font-weight: normal; }

            S Offline
            S Offline
            seee sharp
            wrote on last edited by
            #5

            Thanks Guffa. This information helped me too. I was using the random generation in my program and was thinking the probability of generating last number could be less... but now came to know it does not generate. Intead it generates till one less(as in your example betwen 1-99) Thanks again!!!

            - ashish

            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