Option Explicit
Sub test()
Dim x As Long, y As Long, z As Long
Dim i As Long, a
x = Application.InputBox("Enter starting Random Number", "Random Number Generation", 1, , , , , 1)
y = Application.InputBox("Enter ending Random Number", "Random Number Generation", 1000, , , , , 1)
z = Application.InputBox("How many random numbers" & vbLf & "would you like to generate (<15000)?", _
"Random Number Generation", 100, , , , , 1)
If z = 0 Then Exit Sub
If z > 15000 Then z = 15000
If z > y - x + 1 Then
MsgBox "You specified more numbers to return than " & "are possible in the range!"
Exit Sub
End If
ReDim a(1 To y - x + 1, 1 To 2)
Randomize
For i = x To y
a(i - x + 1, 1) = i
a(i - x + 1, 2) = Rnd
Next
VSortM a, 1, UBound(a, 1), 2
With Cells(1).Resize(z)
.CurrentRegion.ClearContents
.Value = a
End With
End Sub
Private Sub VSortM(ary, LB, UB, ref)
Dim M As Variant, i As Long, ii As Long, iii As Long, temp
i = UB: ii = LB
M = ary(Int((LB + UB) / 2), ref)
Do While ii <= i
Do While ary(ii, ref) < M: ii = ii + 1: Loop
Do While ary(i, ref) > M: i = i - 1: Loop
If ii <= i Then
For iii = LBound(ary, 2) To UBound(ary, 2)
temp = ary(ii, iii): ary(ii, iii) = ary(i, iii)
ary(i, iii) = temp
Next
ii = ii + 1: i = i - 1
End If
Loop
If LB < i Then VSortM ary, LB, i, ref
If ii < UB Then VSortM ary, ii, UB, ref
End Sub
Bookmarks