Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random question 1

Status
Not open for further replies.

sfenx

Programmer
Feb 23, 2001
81
BE
This is the code I use to pick a random number within a range of numbers :
suppose that min = 2 and max = 9
Code:
s = Int((max - min + 1) * Rnd + min)[\code]
My question is how I can get VB to pick specific numbers within this range, i.e. choose randomly between 2, 5, 6, 7 and 9.

Sfenx 8-)
 
It sounds like you are wanting to do a two step randomization.

Step one: Fill an array with a set of random numbers (e.g. 2,5,6,7,9). Note: In this example 5 random numbers have been generated. Array element zero = 2.

Step two: Generate a single random number between 0 and x (x= the number of random numbers generated in step one, which in this example is 5)

 
Could you help me out with a little example here ? I already had step 1 done, but step two isn't very clear to me.
Thanks.
 
I have figured it out myself. Thanks Nantronix.
Still fighting with arrays however.

How can I redim an array(16,2) to an array(8,4) and still preserve the data? I used the preserve statement, but changing the lower bound causes an error. Is there a way to fix this ? :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top