Code:
Sub test()
Dim x As Integer
For x = 0 To 3
MsgBox (ReturnRandomNumber(0, 3, x))
Next x
End Sub
Public Function ReturnRandomNumber(lower As Integer, upper As Integer, turn As Integer) As String
Dim n As Integer, arr() As Variant
Redo:
n = Int((upper - lower + 1) * Rnd + lower)
Debug.Print (n)
ReDim Preserve arr(turn)
For a = lower To upper
If arr(a) <> "" Then
If arr(a) = n Then GoTo Redo
Else
Exit For
End If
Next a
arr(turn) = n
ReturnRandomNumber = n
End Function
But the array is still empty every the function restarts. It fails when I want the array that stores every n to check if n is duplicated.