Computer Science Canada

How do you create random integers in VB 6.0?

Author:  Darkmantis [ Thu Dec 08, 2005 6:11 pm ]
Post subject:  How do you create random integers in VB 6.0?

I am stuck on a game I am making because I have no clue how to make random integers. In turing it is Randint i: 1..6 but I don't know how it is in VB 6.0.

Author:  Tony [ Thu Dec 08, 2005 8:25 pm ]
Post subject: 

Rnd returns a random float.

Author:  Darkmantis [ Fri Dec 09, 2005 6:57 am ]
Post subject: 

Rnd 6
If Rnd = 1 Or 4 Then
creature1.Left = creature1.Left + 300
End If
If Rnd = 2 Or 5 Then
creature1.Left = creature1.Left - 300
End If
If Rnd = 3 Or 6 Then
creature1.Left = creature1.Left
End If

im trying this code but its not working.

Author:  Tony [ Fri Dec 09, 2005 9:35 am ]
Post subject: 

What values does Rnd return?

Author:  pavol [ Fri Dec 09, 2005 10:18 am ]
Post subject: 

anytime i've used the rnd function i store the randomized number in a variable like so: number = Int(Rnd * 6) and then check the number variable for the value
code:
If number = 5 then
'whatever
End If

Author:  Tony [ Fri Dec 09, 2005 10:59 am ]
Post subject: 

Should be pointed out that Int(Rnd * 6) will return numbers from 0 to 5

Author:  pavol [ Fri Dec 09, 2005 11:18 am ]
Post subject: 

if you don't want the zero then just add Int(Rnd *6)+1

Author:  Darkmantis [ Sat Dec 10, 2005 10:28 am ]
Post subject: 

ok thx a lot guys Very Happy


: