That code is just an example of the Fisher-Yates-Knuth random shuffle which has for long been the standard way of producing unbiased, non-repeating random sequences, which is what you appear to want.
https://en.wikipedia.org/wiki/Fisher–Yates_shuffle
It's also considered the fastest method, most efficient with computer storage space and takes minimal numbers of calculations to produce its result. Takes about 1 second to produce 100,000 non-repeating random integers, for example.
Of course it doesn't matter to me which method you prefer for this thread, but if you do any work in this area it may be in your own interests to learn the standard method, which is actually quite easy to understand. And especially so if it's an academic project ...
But if you do really wish to use your indicated preference of the trial and error method of repeating and re-repeating random numbers until you get it right, then a couple of suggestions:
(a) put in a "randomize" line to ensure you don't get repeating patterns of "randomization" when you may not want to.
(b) Instead of using the scripting dictionary (do you really understand how this works?) to filter out repeating integers, try using booleans instead, which are much faster (with integers), probably easier for the average user to understand, and work on all computers (the scripting dictionary won't usually work on a Mac).
A boolean-modified trial-and-error code for example is:
Rich (BB code):
Sub Random4_mod()
'Assumes data range is A1:A4, change to suit
Dim R As Range, d() As Boolean, c As Range, ct As Long
Set R = Range("A1:A4") '<--- change range to suit
ReDim d(4) ' = CreateObject("Scripting.Dictionary")
For Each c In R
Do
c.Value = Int((4 * Rnd) + 1)
If Not d(c.Value) Then '.exists(c.Value) Then
ct = ct + 1
d(c.Value) = True '.Add c.Value, ct
Exit Do
End If
Loop
Next c
End Sub