相关疑难解决方法(0)

Rand()%14仅生成值6或13

每当我运行以下程序时,返回的值总是6或13.

#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;

//void randomLegs();
//void randomPush();
//void randomPull();
//void randomMisc();


int main(int argc, const char * argv[])
{
    srand(time(NULL));
    //randomLegs();
    cout << rand() % 14;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在今天和昨天,我已经将程序运行了近百次.

谁能告诉我我做错了什么?

谢谢.

编辑:顺便说一句,如果我将rand()的范围改为13或15,它就可以了.

c++ random srand

14
推荐指数
2
解决办法
916
查看次数

标签 统计

c++ ×1

random ×1

srand ×1