#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void shuffle(int *array, int tamanho) { //sorteia grantidamente único - algoritmo Fisher-Yates
for (int i = tamanho - 1; i > 0; i--) {
int j
= rand() % (i
+ 1); int tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
}
int main() {
int roll[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; //cria os valore permitidos
shuffle(roll, 8); //embaralha
int resultado[6];
for (int i = 0; i < 3; i++) { //só escolhe 3 números conforme a definição
resultado[i] = roll[i];
resultado[i + 3] = roll[i]; //repete o número
}
shuffle(resultado, 6); //embaralha os números que estavam agrupados
for (int i
= 0; i
< 6; i
++) printf("%d ", resultado
[i
]); }
//https://pt.stackoverflow.com/q/315483/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx0aW1lLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnZvaWQgc2h1ZmZsZShpbnQgKmFycmF5LCBpbnQgdGFtYW5obykgeyAvL3NvcnRlaWEgZ3JhbnRpZGFtZW50ZSDDum5pY28gLSBhbGdvcml0bW8gRmlzaGVyLVlhdGVzCiAgICBmb3IgKGludCBpID0gdGFtYW5obyAtIDE7IGkgPiAwOyBpLS0pIHsKICAgICAgICBpbnQgaiA9IHJhbmQoKSAlIChpICsgMSk7CiAgICAgICAgaW50IHRtcCA9IGFycmF5W2pdOwogICAgICAgIGFycmF5W2pdID0gYXJyYXlbaV07CiAgICAgICAgYXJyYXlbaV0gPSB0bXA7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgc3JhbmQodGltZShOVUxMKSk7CiAgICBpbnQgcm9sbFs4XSA9IHsgMCwgMSwgMiwgMywgNCwgNSwgNiwgNyB9OyAvL2NyaWEgb3MgdmFsb3JlIHBlcm1pdGlkb3MKICAgIHNodWZmbGUocm9sbCwgOCk7IC8vZW1iYXJhbGhhCiAgICBpbnQgcmVzdWx0YWRvWzZdOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAzOyBpKy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