C语言生成三个不相等的随机数

#include 
#include 
#include 

#define MAX 8

int main()
{
    srand((unsigned)time(NULL));
    int i, j, k;

    do
    {
        i = rand() % MAX;
        j = rand() % MAX;
        k = rand() % MAX;
    }while(i == j || i == k || j == k);

    printf("i = %d\n", i);
    printf("j = %d\n", j);
    printf("k = %d\n", k);
    return 0;
}

你可能感兴趣的:(c)