How to pick a random number from given set of numbers
Hello everyone. I am in a last year of gymnasium and I really enjoy working with computers. Specialy while programming. I am a beginner (started few weeks ago) and I actually made my first mathematical program but with no random number generator, and just 10 expressions. After formatting my computer my first program was lost so I decided to make a new one with some improvments involved. With a help from a friend (which brought me into VB and tought me how VB actually works, but this is all I know) I made form for summating, form for subduction and form for multiplication. Now I am stuck at from for dividing.
My idea is to make something like this:
Program auto-generates number from 1-10 and puts it into label2. Then with a statments program randomly chooses one number from given set of numbers and puts it into label2.
//Program generates number 5, so label2.text = "5"
If label2.text = "5" Then label1.text = [Solution] (So label1.text should be 5, 10, 15, 20, 25, 30, 35, 40, 45 or 50.)
Re: How to pick a random number from given set of numbers
A simple way to get a random number from a given group of numbers is to put those numbers into a list or array and then choose a random number from 0 to number of items in the list -1 which will give you a number that you can then use as an index to get the number from the list that is in that position. So in your example if the random number was 4 then it would grab the item at list index 4 which would be 25
btw what does gymnasium have to do with computers or programming?
call it's Next() method with a min and max, respectively being, 0, and the arrays Length for the exact number of elements in that array. This function would return the index, and you would use it to retrieve the element at that index being the "random" value chosen as DataMiser had mentioned.