If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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.

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

Re: How to pick a random number from given set of numbers

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.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.