PDA

View Full Version : Random Function



Lalaji
03-01-2008, 09:41 PM
Is there a random function in vb6?

X := Random (10);

XcanadamanX
03-02-2008, 03:45 PM
there is Rnd but it returns a random number between 0 and 1. you can modify this though to create your own function

Lalaji
03-02-2008, 05:04 PM
How does it go?

If Rnd IntX Then
'w\e
End If

XcanadamanX
03-03-2008, 09:12 PM
that are you trying to do?
try this:


Public Function Random(Range As Double, RoundNumber As Boolean)
If RoundNumber = True Then
Random = Round(Rnd * Range) + 1
ElseIf RoundNumber = False Then
Random = (Rnd * Range) + 1
End If
End Function

found it on some site. try it out see if it works

Zigon
06-09-2008, 10:08 PM
say you wanted a random number between 1 to 10
First, be sure to add Randomize to your forum load, I don't remember why(So you can use the rnd funtion?)


Private Sub Form_Load()
Randomize


In your button or whatever you want


dim i as integer
i = (rnd * 10) + 1


The reason you add 1 at the end is because vb uses 0's. * 10 will give you a number between 0-9, so +1 will give you 1-10!