dimanche 14 janvier 2018

How not to repeat random numbers until all are used?

I have a code that I am trying to add support so it can not repeat the numbers until all have been used.

each time the random_type function is used it generates a random number up to 10, which I am looking for is a way the numbers will not repeat until all have been used.

Code:

#define LOOP_MACRO(cnt, type) \
    for ((cnt) = 0; (cnt) < 10; ++(cnt)) \
        if (((type) & 1<<(cnt)) == 0) { \
            continue; \
        } else


void random_type(int type, int value) {
    int i;
    uint32 type_select = select_type(type);

    LOOP_MACRO(i, type_select) {
        SelectT->type[i] += value;
    }
}

int main ()
{
    int randType = rand()%10;
    random_type(randType, 80);
]

Example:

10,5,1,3,2,6,9,4,8,7
2,9,1,4,10,7,5,8,3,6




Aucun commentaire:

Enregistrer un commentaire