Shuffle an Array


@MindGeek I'm not super sure that I understand your question. However, if you can convince yourself that the brute force analysis is correct, it might help to think about how FisherYates is actually almost identical to it. Essentially, after the ith iteration of the swapping loop,
array[:i]
(inclusive) is the result (so far) of the algorithm, whilearray[i+1:]
is the "hat", oraux
from the brute force solution.

I have a question about "we generate a random integer between the current index and the last index of the array" . Can we use a random integer within the range of 0 and the current index+1. i.e. rand.nextInt(i+1) in the shuffle method?? @emptyset Is there any advantage of using current index and the last index of the array? Like mathematicaly?

@PremiumLab_ There is no mathematical difference. It is possible that one method is superior by a constant factor due to some lowlevel CPU reason, but certainly not significantly.