PDA

View Full Version : Function to return Random Values



Movian
06-05-2009, 08:26 AM
Hey,
i just finished producing a func that returns random values of set types and thought i would share for multiple reasons.

1) hopefully this may help other people looking to do similar things
2) people can point out how to optimize portions.
3) someone else may advance on this and product additional types to return random examples of

well here is what i have :)

Public Enum RandomType
RandText = 1
RandTel = 2
RandSocial = 3
RandEmail = 4
End Enum
Public Function returnrand(func As RandomType)
Dim lenrand As Integer, charrand As Integer, counter As Integer, result As String
Select Case func
Case 1
lenrand = Int((10 - 1 + 1) * Rnd + 1)
For counter = 0 To lenrand
charrand = Int((122 - 97 + 1) * Rnd + 97)
result = result & Chr(charrand)
Next
Case 2
For counter = 1 To 10
result = result & CStr(Int((9 - 0 + 1) * Rnd + 0))
Next
Case 3
For counter = 1 To 9
result = result & CStr(Int((9 - 0 + 1) * Rnd + 0))
Next
Case 4
lenrand = Int((10 - 1 + 1) * Rnd + 1)
For counter = 0 To lenrand
charrand = Int((122 - 97 + 1) * Rnd + 97)
result = result & Chr(charrand)
Next
result = result & "@"
lenrand = Int((10 - 1 + 1) * Rnd + 1)
For counter = 0 To lenrand
charrand = Int((122 - 97 + 1) * Rnd + 97)
result = result & Chr(charrand)
Next
result = result & ".com"
End Select
returnrand = result
End Function