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. Random Number from 6 to 86

Random Number from 6 to 86

Scheduled Pinned Locked Moved C#
csharphelptutorialquestionlounge
12 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.
  • S Offline
    S Offline
    Sylenze
    wrote on last edited by
    #1

    Hello... I'm new to C# and i want to train my skills with programming an Application that looks at 3 progressbars and make the values of them "even", like if pbar1's value is 34, it becomes 30, but if it is 36, it becomes 40. I use it to test the Fuzzy logic dot net =x Now this is the code i need help with: private void button2_Click(object sender, EventArgs e) { if (chkbx1.Checked) { vbar1.Value = Random; } } "button2" is my Object for generating random Numbers for those pbars with checked checkboxes... Now how to get that random Value from 6 to 86? please help =(

    P H 2 Replies Last reply
    0
    • S Sylenze

      Hello... I'm new to C# and i want to train my skills with programming an Application that looks at 3 progressbars and make the values of them "even", like if pbar1's value is 34, it becomes 30, but if it is 36, it becomes 40. I use it to test the Fuzzy logic dot net =x Now this is the code i need help with: private void button2_Click(object sender, EventArgs e) { if (chkbx1.Checked) { vbar1.Value = Random; } } "button2" is my Object for generating random Numbers for those pbars with checked checkboxes... Now how to get that random Value from 6 to 86? please help =(

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Use the System.Random class... Paul

      S 1 Reply Last reply
      0
      • P pmarfleet

        Use the System.Random class... Paul

        S Offline
        S Offline
        Sylenze
        wrote on last edited by
        #3

        System.Random is the same as Random D: someone please explain me =(

        P 1 Reply Last reply
        0
        • S Sylenze

          System.Random is the same as Random D: someone please explain me =(

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          Call the overload of System.Random.Next that accepts 2 arguments. The first is your min value, the second is your max value. This is all explained in the documentation... Paul

          1 Reply Last reply
          0
          • S Sylenze

            Hello... I'm new to C# and i want to train my skills with programming an Application that looks at 3 progressbars and make the values of them "even", like if pbar1's value is 34, it becomes 30, but if it is 36, it becomes 40. I use it to test the Fuzzy logic dot net =x Now this is the code i need help with: private void button2_Click(object sender, EventArgs e) { if (chkbx1.Checked) { vbar1.Value = Random; } } "button2" is my Object for generating random Numbers for those pbars with checked checkboxes... Now how to get that random Value from 6 to 86? please help =(

            H Offline
            H Offline
            Hessam Jalali
            wrote on last edited by
            #5

            just create a new instance of Random class like Random rnd=new Random(); use the next method for generating random number int randomNumber=rnd.Next(6,86); good luck

            S 1 Reply Last reply
            0
            • H Hessam Jalali

              just create a new instance of Random class like Random rnd=new Random(); use the next method for generating random number int randomNumber=rnd.Next(6,86); good luck

              S Offline
              S Offline
              Sylenze
              wrote on last edited by
              #6

              omg there is no next method... Maybe i forgot a using directive? there are only 2 methods on Random... it's Equals and ReferenceEquals

              S 1 Reply Last reply
              0
              • S Sylenze

                omg there is no next method... Maybe i forgot a using directive? there are only 2 methods on Random... it's Equals and ReferenceEquals

                S Offline
                S Offline
                Sylenze
                wrote on last edited by
                #7

                ok nevermind i got it thanks!

                S 1 Reply Last reply
                0
                • S Sylenze

                  ok nevermind i got it thanks!

                  S Offline
                  S Offline
                  Stefan Troschuetz
                  wrote on last edited by
                  #8

                  Please consider that the second parameter is the exclusive upper bound of the random variate i.e. rnd.Next(6,86); will generate random numbers between 6 and 85. If you want the 86 to be generated too, the second parameter must be 87.


                  "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                  www.troschuetz.de

                  S 1 Reply Last reply
                  0
                  • S Stefan Troschuetz

                    Please consider that the second parameter is the exclusive upper bound of the random variate i.e. rnd.Next(6,86); will generate random numbers between 6 and 85. If you want the 86 to be generated too, the second parameter must be 87.


                    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                    www.troschuetz.de

                    S Offline
                    S Offline
                    Sylenze
                    wrote on last edited by
                    #9

                    Ok i've got another problem... Now if you click on the "Make even!" button (for rounding up and off to 10~values, like 10 20 30 40) i don't know what to put it... I mean it should also be usable in other things like unknown values from 1~25233636 for example. it's currently this: #region Vbar1 if (vbar1.Value = 6-10) { vbar1.Value = 10; } #endregion 1. i don't know how to make it like "from 6 to 10", the - isn't working O__O 2. it's not really flexible and i have to make like 9 if handlers for every pbar... if (vbar1.Value > 6 & < 10 ) isn't working too...

                    S 1 Reply Last reply
                    0
                    • S Sylenze

                      Ok i've got another problem... Now if you click on the "Make even!" button (for rounding up and off to 10~values, like 10 20 30 40) i don't know what to put it... I mean it should also be usable in other things like unknown values from 1~25233636 for example. it's currently this: #region Vbar1 if (vbar1.Value = 6-10) { vbar1.Value = 10; } #endregion 1. i don't know how to make it like "from 6 to 10", the - isn't working O__O 2. it's not really flexible and i have to make like 9 if handlers for every pbar... if (vbar1.Value > 6 & < 10 ) isn't working too...

                      S Offline
                      S Offline
                      Stefan Troschuetz
                      wrote on last edited by
                      #10

                      Divide the number by ten, round it and finally multiply with ten:

                      int x = 15;
                      x = (int)(Math.Round(x / 10.0) * 10.0);


                      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                      www.troschuetz.de

                      S 1 Reply Last reply
                      0
                      • S Stefan Troschuetz

                        Divide the number by ten, round it and finally multiply with ten:

                        int x = 15;
                        x = (int)(Math.Round(x / 10.0) * 10.0);


                        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                        www.troschuetz.de

                        S Offline
                        S Offline
                        Sylenze
                        wrote on last edited by
                        #11

                        wow you'r really good in c# =O Sorry i'm new to all this and i don't have much time for learning it... hmm #region Vbar1 vbar1.Value x = 15; x = (vbar1.Value)(Math.Round(x / 10.0) * 10.0); #endregion the debugger says vbar1 is a field but it's used like a type @_@ and what's the 15 for? -- modified at 14:15 Tuesday 14th August, 2007

                        S 1 Reply Last reply
                        0
                        • S Sylenze

                          wow you'r really good in c# =O Sorry i'm new to all this and i don't have much time for learning it... hmm #region Vbar1 vbar1.Value x = 15; x = (vbar1.Value)(Math.Round(x / 10.0) * 10.0); #endregion the debugger says vbar1 is a field but it's used like a type @_@ and what's the 15 for? -- modified at 14:15 Tuesday 14th August, 2007

                          S Offline
                          S Offline
                          Sylenze
                          wrote on last edited by
                          #12

                          okay thanks all for helping me =] here's the source and exe: hosted.filefront.com/sylenze

                          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