DeanWilliams
Programmer
Hi,
Sorry if this is a bit long.
I have written a function that returns a random string of a random length. I used the random (Rnd) function to create these strings:
The user specifies the shortest length they want the string to be and the function then determines the length at random between that number and 20. Then each character is randomly chosen from upper/lower case and number characters.
I would have thought the results would be completely random, but have found that I get the EXACT same strings sometimes when I use it!!!
I have been using it to create PID's for Access security, so it is not ideal if these strings can be determined again at a later stage.
I hope that makes sense, but does anyone know why this happens? And does anyone know how to generate totally random numbers?
This is the main part of the code:
Dean.
Sorry if this is a bit long.
I have written a function that returns a random string of a random length. I used the random (Rnd) function to create these strings:
The user specifies the shortest length they want the string to be and the function then determines the length at random between that number and 20. Then each character is randomly chosen from upper/lower case and number characters.
I would have thought the results would be completely random, but have found that I get the EXACT same strings sometimes when I use it!!!
![[sadeyes] [sadeyes] [sadeyes]](/data/assets/smilies/sadeyes.gif)
I have been using it to create PID's for Access security, so it is not ideal if these strings can be determined again at a later stage.
I hope that makes sense, but does anyone know why this happens? And does anyone know how to generate totally random numbers?
This is the main part of the code:
Code:
[COLOR=blue]
Function CreatePID(intLBound As Integer, strUser As String, _
TypePID As PIDType, Optional strLogFile As String) As String
On Error GoTo Err_CreatePID
Dim strResult As String
Dim intLength As Integer
Dim strCharSet As String
Dim intChar As Integer
Dim X As Integer
Dim strType As String
strCharSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
intLength = Int((20 - intLBound + 1) * Rnd + intLBound)
For X = 1 To intLength
intChar = Int((Len(strCharSet) - 1 + 1) * Rnd + 1)
strResult = strResult & Mid$(strCharSet, intChar, 1)
Next
Debug.Print strUser, strResult
' ....
' ....
[/color]
Dean.