SRL Archive - C#/Visual Basic Help and Tutorials

Random Function


Lalaji

2008-03-01 16:41:03

Is there a random function in vb6?

X := Random (10);

XcanadamanX

2008-03-02 10:45:46

there is Rnd but it returns a random number between 0 and 1. you can modify this though to create your own function

Lalaji

2008-03-02 12:04:45

How does it go?

If Rnd IntX Then
'w\e
End If

XcanadamanX

2008-03-03 16:12:45

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

2008-06-09 18:08:05

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!