I will start by admitting that I haven't actually done the maths on the probability of a repeat but this just seems wrong.
I needed a randomly generated sequence of chars and used the following code as found on these forums with minor additions to change the range of chars that might be selected.
Given the possible permutations available here I would have thought the possibilities should be massive however I am getting many repeated values even on a repetitively small sample.
To try it out enter the following in cell A1
and then Fill down to cell A100. You will see that you get numerous repeats easier with conditional formatting.
So my question, please, is why and how can I avoid it as really I could do with unique values?
Thanks in advance.
John
I needed a randomly generated sequence of chars and used the following code as found on these forums with minor additions to change the range of chars that might be selected.
Code:
Public Function RandomizeF(Num1 As Integer, Num2 As Integer)
Dim Rand As String, RandTemp As String
Application.Volatile
getLen = Int((Num2 + 1 - Num1) * Rnd + Num1)
Do
i = i + 1
Do
Randomize
RandTemp = Int((89) * Rnd + 33)
Loop Until (RandTemp = 33) Or (RandTemp >= 35 And RandTemp <= 38) Or (RandTemp >= 47 And RandTemp <= 57) Or (RandTemp >= 64 And RandTemp <= 90) Or (RandTemp >= 97)
Rand = Rand & Chr(RandTemp)
Loop Until i = getLen
RandomizeF = Rand
End Function
Given the possible permutations available here I would have thought the possibilities should be massive however I am getting many repeated values even on a repetitively small sample.
To try it out enter the following in cell A1
Code:
=RandomizeF(8,10)
So my question, please, is why and how can I avoid it as really I could do with unique values?
Thanks in advance.
John