超级好用的C++随机数生成函数
一、下面的代码可以封装成头文件,文件名是util.h
#ifndef _OJ_DATA_UTIL_HEAD_
#define _OJ_DATA_UTIL_HEAD_
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
namespace oj_tools {
void init() {
srand(time(NULL)); }
LL randLong() {
LL x = rand();
LL y = rand();
return (x << 16) + y;
}
inline double randDouble() {
return (double)rand() / RAND_MAX; }
inline int randInt(int start, int end) {
return (int)((end - start + 1) * randDouble() + start);
}
vector<int> randIntsNormalDistribution(int start, int end, int size = 10) {
vector<int> v(size, 0);
for