Click to See Complete Forum and Search --> : The power of RND
rino_2
Jan 10th, 2000, 01:49 AM
Hi,
I'm making a program that will need to randomize two numbers. The problem is that the numbers are not close to each other like 1 to 2. The numbers are something like 2 to 6. But you understand, I only want to random one of those two numbers. If I said:
intNumber = int((6 * RND) + 1)
I would get all the numbers in between aswell. I hope you understande what I'm saying here. I only want to random 2 or 6 using the random function. Could you please help?
Thank you!
badgers
Jan 10th, 2000, 01:53 AM
would this work for you?
If int((6 * RND) + 1)<3 then
intNumber = 2
Else
intNumber = 6
End If
rino_2
Jan 10th, 2000, 02:21 AM
Hi badgers,
Maybe I should have been a little more clear in my question. I just used 2 and 6 as an example. Really I want to randondomize one of the numbers 2 3 5 7 and 9. So I'm not too sure that way would work. I will be happy to hear any other ways you may know.
Thanks
MartinLiss
Jan 10th, 2000, 02:39 AM
I think we are having a problem understanding what you mean by "randomize one of the numbers". Can you give an example of the results you would expect?
------------------
Marty
TheMadMonk
Jan 10th, 2000, 02:57 AM
just do like badgers said, but split the resulst into 5 parts
intNumber = int((5 * RND) + 1)
then:
if intNumber = 1 then Result = 2
if intNumber = 2 then Result = 3
if intNumber = 3 then Result = 5
if intNumber = 4 then Result = 7
if intNumber = 5 then Result = 9
(a case statement would be easier though)
QWERTY
Jan 10th, 2000, 02:58 AM
or use this:
Dim Done As Boolean
Dim myNum As Integer
Do While Not Done
myNum = Int((9 * Rnd) + 1)
If myNum <> 2 And myNum <> 3 And myNum <> 5 And myNum <> 7 And myNum <> 9 Then
Done = False
Else
Done = True
End If
Loop
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.