I'm a little confused. I was under the impression this was an elementary problem. *shrug*
Here was me thinking for loops were intended to iterate a predetermined (whether constant or variable) number of times. If you do insist on using the wrong keyword, there is no point endlessly increasing and decreasing the loop counter.
Code:
for(new i=1; i < 27; )
{
new index = random_num(0, sizeof(array)-1))
if(array[index] == -1)
array[index] = i++
}
I wrote what you're doing in VB.NET (because I'd forgotten how disgusting it was) and these are the number of iterations it took.
172 52 99 63 197 88 109 103 95 54 127 88 68 74 107 138 63 111 123 76
I have a suspicion that the .NET pseudorandom number generator is better in terms of uniform distribution than random_num() and so you might find it takes longer.
The way I'd achieve this is to swap random elements around (you can XOR the values if you're partial to that sort of thing). You can either call random_num() twice per swap or use modulus. It's up to you to decide how many iterations is sufficient. I'm sure you don't need me to code an example. You've probably settled for what's above anyway.
__________________