I have an array. I need the array’s element order randomized.
So, if I have an array like this:
a[0] = "abc"
a[1] = "def"
a[2] = "ghi"
a[3] = "jkl"
It might be randomized like this:
a[0] = "jkl"
a[1] = "def"
a[2] = "abc"
a[3] = "ghi"
You’re provided with a function which returns a random number between 0 and N, where N is the number you provide as a parameter.
As always, your solution should execute quickly and be efficient.

I’m no algorithm guru by any stretch of the imagination, but I have enjoyed working on these questions you’ve been throwing out there.
I came up with a solution which I *think* is reasonable and was performant over huge sets. Seems deceptively simple though. So, I was curious what other solutions there were to this problem.
My approach, in a nutshell, was to iterate over the list, once. For each element in the array I requested a new random number and used that number as an index into the array. I then swapped the contents of that index value with the current slot. Lather, rinse, repeat.
The problem statement didn’t specify whether I could shuffle the contents of the passed in array or whether I had to make a copy. I opted for shuffling in place to keep things easier.
Since my approach comment kinda spoils the interview question format I’m not sure you’ll want to post this. But I would be interested in knowing how others approach this.
Love your blog, keep em coming!