Random Number from 6 to 86
-
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 =( -
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 =( -
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 =(just create a new instance of Random class like
Random rnd=new Random();
use the next method for generating random numberint randomNumber=rnd.Next(6,86);
good luck -
just create a new instance of Random class like
Random rnd=new Random();
use the next method for generating random numberint randomNumber=rnd.Next(6,86);
good luck -
omg there is no next method... Maybe i forgot a using directive? there are only 2 methods on Random... it's Equals and ReferenceEquals
-
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
-
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
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... -
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...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
-
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
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 -
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, 2007okay thanks all for helping me =] here's the source and exe: hosted.filefront.com/sylenze