C的随机数用法

rand()

#include <stdio.h>
#include <stdlib.h>
int main()
{
    for (int i = 0; i < 10; i++)
    {
        printf("%d\n",rand());
    }
    system("pause");
    return EXIT_SUCCESS;
}

C的随机数用法

#include <stdio.h>
#include <stdlib.h>
int main()
{
    for (int i = 0; i < 10; i++)
    {
        printf("%d\n",rand()%10);
    }
    system("pause");
    return EXIT_SUCCESS;
}

C的随机数用法

 指定随机数的生成范围例如生成8以内的随机数---只不过....程序每次运行时都是生成这几个货

#include <stdio.h>
#include <stdlib.h>
int main()
{
    srand(8);
    for (int i = 0; i < 10; i++)
    {
        printf("%d\n",rand()%10);
    }
    system("pause");
    return EXIT_SUCCESS;
}

C的随机数用法

 

上一篇:pause 命令


下一篇:GC 设计与停顿