#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int randomInteger(int low, int high)
{
int k;
double d;
d
= (double)rand() / ((double)RAND_MAX
+ 1); k = (int) (d * (high - low + 1));
return low + k;
}
void permutacaoAleatoria(int v[], int n) {
int r, k, t;
for (k = n - 1; k > 0; k--) {
r = randomInteger(0, k);
t = v[k], v[k] = v[r], v[r] = t;
}
}
void randomize()
{
}
int main() {
int nums[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
randomize();
permutacaoAleatoria(nums, 10);
int i;
printf("Valores no vetor: ["); for (i = 0; i < 10; i++)
printf("%s%d", (i
!= 0 ? ", " : ""), nums
[i
]); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCmludCByYW5kb21JbnRlZ2VyKGludCBsb3csIGludCBoaWdoKQp7CglpbnQgazsKCWRvdWJsZSBkOwoJZCA9IChkb3VibGUpcmFuZCgpIC8gKChkb3VibGUpUkFORF9NQVggKyAxKTsKCWsgPSAoaW50KSAoZCAqIChoaWdoIC0gbG93ICsgMSkpOwoJcmV0dXJuIGxvdyArIGs7Cn0KCnZvaWQgcGVybXV0YWNhb0FsZWF0b3JpYShpbnQgdltdLCBpbnQgbikgewoJaW50IHIsIGssIHQ7Cglmb3IgKGsgPSBuIC0gMTsgayA+IDA7IGstLSkgewoJCXIgPSByYW5kb21JbnRlZ2VyKDAsIGspOwoJCXQgPSB2W2tdLCB2W2tdID0gdltyXSwgdltyXSA9IHQ7Cgl9Cn0KCnZvaWQgcmFuZG9taXplKCkKewoJc3JhbmQodGltZShOVUxMKSk7Cn0KCmludCBtYWluKCkgewoKCWludCBudW1zW10gPSB7IDAsIDEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDkgfTsKCXJhbmRvbWl6ZSgpOwoJcGVybXV0YWNhb0FsZWF0b3JpYShudW1zLCAxMCk7CglpbnQgaTsKCXByaW50ZigiVmFsb3JlcyBubyB2ZXRvcjogWyIpOwoJZm9yIChpID0gMDsgaSA8IDEwOyBpKyspCgkJcHJpbnRmKCIlcyVkIiwgKGkgIT0gMCA/ICIsICIgOiAiIiksIG51bXNbaV0pOwoJcHJpbnRmKCJdIik7CglyZXR1cm4gMDsKfQ==
Valores no vetor: [6, 1, 0, 4, 7, 8, 5, 2, 9, 3]