目錄
一:C語言中的隨機數
二:C++中的隨機數
1. 生成隨機數的例子
2. 隨機數引擎
3. 隨機數引擎適配器
4. C++中預定義的隨機數引擎,引擎適配器
5. 隨機數分布
一:C語言中的隨機數
<stdlib.h>//初始化隨機種子
srand(static_cast<unsigned int>(time(nullptr)));//生成隨機數
cout << rand() << endl;//生成一個區間的內隨機數(min, max)
return static_cast<int>(rand() % (max + 1UL - min)) + min;//生成100內隨機數
int num = rand() % 100;//生成1-100內隨機數
int num = rand() % 100 + 1;
二:C++中的隨機數
1. 生成隨機數的例子
include <random>
#include <map>
#include <iostream>int main()
{static const int NUM = 1000000;//第一步 產生隨機種子std::random_device seed;//第二步:使用隨機數引擎生成器std::