Library code snippets
Generating Random Numbers
VB provides a simple little function that lets you generate your own random (or as random as you can get on a PC!) numbers, called Rnd. Below is an example. For more information, click here.
Private Sub cmdRollDice_Click()
Dim intResult As Integer
'// Initializes the random-number generator, otherwise each
time you run your
'// program, the sequence of numbers will be the same
Randomize
intResult = Int((6 * Rnd) + 1) '// Generate random value
between 1 and 6.
MsgBox "Dice: " & intResult '// Display result
End Sub
Private Sub cmdGetRandomNumber_Click()
Dim intResult As Integer
'// Initializes the random-number generator, otherwise each
time you run your
'// program, the sequence of numbers will be the same
Randomize
intResult = Int((100 * Rnd) + 1) '// Generate random value
between 1 and 100.
MsgBox "Random number: " & intResult '// Display result
End Sub
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Goes to the very page it's on. Oops?
This thread is for discussions of Generating Random Numbers.