Dim RandomClass As New Random()
Dim rndNumber As Integer
rndNumber = (RandomClass.Next(01, 99))
This will choose a random number between 1 and 99. Keep in mind, when doing images, you should stick to a proper format and if you have less than 100 images, and plan on keeping it that way, include one zero in place of the first digit:
01 - 99
001 - 999
0001 - 9999
Now you don't honestly HAVE to follow this, but it prevents errors dramatically. Plus, if you get an error, do you really want to go through and rename a thousand images? :)
Here is something that you should probably use to grab the image:
Keep in mind I use T_*.jpg for all my "thumbnails".
Public Function RndImage() As String
Dim rnd As New Random()
'The below is for image names that start with "T_" and are jpeg.
Dim ID As String = "T_*.jpg"
Dim IDArr() As String = ID.split("*")
Dim images() As String = System.IO.Directory.GetFiles((Server.MapPath("\images\"), ID)
Dim imageToDisplay As String
if CountPhotos(ID) < 1 then imageToDisplay = "nopicture"
Do While Len(imageToDisplay) < 1
imageToDisplay = images(rnd.Next(images.Length))
Return ("\images\" & IDArr(0) & imageToDisplay & IDArr(1))
Public Function CountPhotos(ByVal ID As Long) As Integer
Dim numero As Integer = 0
Dim strPath As String = (Server.MapPath("\images\") & ID)
Dim strFiles As String = Dir(strPath)
Do Until Len(strFiles) = 0
numero += 1
if numero > 0 then exit do
CountPhotos = numero
This code is untested, so let me know if you have problems.