C 我可以做什么使整数每次随机

C 我可以做什么使整数每次随机,c,random,int,C,Random,Int,我创建了一个小猜谜游戏,你需要在3次尝试中猜一个数字,否则你会失败。现在的问题是,每次我运行程序时,我能做些什么使整数随机 下面是一个代码: #include <stdio.h> #include <stdlib.h> int main() { int sN = 4; int g; int gC = 0; int gL = 3; int ofG = 0; while(g != sN && ofG == 0

我创建了一个小猜谜游戏,你需要在3次尝试中猜一个数字,否则你会失败。现在的问题是,每次我运行程序时,我能做些什么使整数随机

下面是一个代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int sN = 4;
    int g;
    int gC = 0;
    int gL = 3;
    int ofG = 0;

    while(g != sN && ofG == 0)
    {
        if(gC < gL)
        {
            printf("Guess a number[1-10]: ");
            scanf("%d", &g);
            gC++;
        }
        else
        {
            ofG = 1;
        }
    }
    if(ofG == 1)
    {
        printf("You Failed! [Out of guesses]\n");
        printf("Secret number was (%d)\n", sN);
    }
    else
    {
        printf("Congratulations! You win!");
    }

  return 0;
}
但是我以前从未使用过它,所以我非常感谢您的帮助。

\include
#include <time.h>
#include <stdlib.h>

srand(time(NULL));   // Initialization, should only be called once.

/* random int between 0 and 9 */
int r = rand() % 10;
#包括 srand(时间(空));//初始化,只应调用一次。 /*0到9之间的随机整数*/ int r=rand()%10;
谢谢您,先生!;)
#include <time.h>
#include <stdlib.h>

srand(time(NULL));   // Initialization, should only be called once.

/* random int between 0 and 9 */
int r = rand() % 10;