Selecting N random numbers. I was having a chat with my friend. We were discussing the problem of producing an array of size $N$ filled with random numbers from $0$ to $N - 1$.
Here by filled with random numbers from $0$ to $N - 1$ , I mean,


*

*Every number in the array should have been randomly selected with an equal probability of $1/N$


I suggested this,


*

*Assuming I have a way to uniformly generate random number between $[0, 1)$, say $Rnd()$

*Fill each element in the array as, $floor(Rnd() * N)$


My friend said this,


*

*Assuming I have a way to shuffle the array.

*Fill the array with numbers $0 .. N - 1$ at the indices $0 .. N-1$

*Do a shuffle on the array.


My friend claims that his method is better because it ensures that every number between $0 .. N - 1$ will occur once and only once. Hence stratifying, the equal probability requirement.
Another difference that I see here is that in the way I suggested, it is possible for a number to be chosen 2 times whereas this is not possible in my friend's way. So the results each of our methods produce are different.
Given that we just have to produce an array of size $N$ which can only contain numbers between $0 .. N-1$ and the probability of occurrence of any number is equal, $1/N$. I couldn't find anything wrong with either of these methods though they are different and produce different results.
Who here, if any, is wrong and why ? Or are we both wrong ?
 A: Your definition of "filled with random numbers from $0$ to $N-1$" specifies the marginal probability distribution of each entry
(that is to say, if you look at any entry individually while ignoring
the others, what is the probability of each outcome for that entry), 
but it says nothing about the dependence of different entries on each other.
The procedure you chose generates a set of $N$ iid (independent,
identically distributed) uniform random variables on the set 
$[0..(N-1)]$.
But if you leave out the word "independent" (which your definition did
not mention or even indirectly imply), there are many other
sets of identically distributed uniform random variables on $[0..(N-1)]$.
Your friend's distribution is one such distribution.
Here's another such distribution:
choose a number $X$ with uniform probability from $[0..(N-1)]$.
Fill each entry in the array with $X$ (all entries the same value).
And another:
choose a number $X$ with uniform probability from $[0..(N-1)]$.
Fill entry $k$ in the array, $0 \leq k < N$,
with $X + k \bmod N$.
(That is, if $X+k<N$, let entry $k$ be $X+k$; otherwise let entry
$k$ be $X+k-N$.)
Your distribution is more "interesting" than either of those.
So is your friend's distribution.
In fact, I would say that the two of you have picked the two
most obviously desirable distributions fitting your description;
each of these distributions is useful for different things,
so I would not say one is better than the other.
A: You friend is correct in arguing that every number between $0$ and $N−1$ will occur once and only once, but he/she is wrong in arguing that this fact will ensure the equal-probability requirement.
For this, you both need to understand that the equal-probability requirement means that each one of the $n!$ different arrangements of the array must be generated with an equal probability (of $1/n!$).
So your friend's shuffling method should be designed carefully in order to ensure equal probability.
One way to do this (as very often appears in software-engineering job interviews by the way):


*

*Repeat for $m=0$ to $n-1$:


*

*Choose a random index $k$ from the range $[m+1,n-1]$

*Swap between element at entry $m$ and element at entry $k$


