I am going to assume that random(i) returns a random greater than or equal to 0 and less than i. If this is not the case the following comment will not be correct.

Your current code will first swap Array[1] with Array[0] to produce {1,0,2} and then swap Array[2] with either Array[0] or Array[1] to produce either {2,0,1} or {1,2,0}.

Try this instead:

for (int i = 2, i > 0 ,i--)

{

int r = random(i + 1);

int temp = Array[i];

Array[i] = Array[r];

Array[r] = temp;

}

On the first iteration this will produce one of:

{0,1,2} {0,2,1} {2,1,0}

And on the second will produce one of:

{0,1,2} {1,0,2} {0,2,1} {2,0,1} {2,1,0} {1,2,0}

Let me know if my first assumption was wrong and I will fix the algorithm for you.

Your current code will first swap Array[1] with Array[0] to produce {1,0,2} and then swap Array[2] with either Array[0] or Array[1] to produce either {2,0,1} or {1,2,0}.

Try this instead:

for (int i = 2, i > 0 ,i--)

{

int r = random(i + 1);

int temp = Array[i];

Array[i] = Array[r];

Array[r] = temp;

}

On the first iteration this will produce one of:

{0,1,2} {0,2,1} {2,1,0}

And on the second will produce one of:

{0,1,2} {1,0,2} {0,2,1} {2,0,1} {2,1,0} {1,2,0}

Let me know if my first assumption was wrong and I will fix the algorithm for you.