forked from skyfireitdiy/sflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sf_random.hpp
46 lines (38 loc) · 1.19 KB
/
sf_random.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @version 1.0.0
* @author skyfire
* @mail skyfireitdiy@hotmail.com
* @see http://github.com/skyfireitdiy/sflib
* @file sf_random.hpp
* sflib第一版本发布
* 版本号1.0.0
* 发布日期:2018-10-22
*/
#pragma once
#include "sf_random.h"
namespace skyfire {
inline sf_random::sf_random() {
e__ = std::make_shared<std::default_random_engine>(rd__());
}
inline int sf_random::get_int(int min, int max) {
std::uniform_int_distribution<int> ed(min, max);
return ed(*e__.get());
}
inline double sf_random::get_double(double min, double max) {
std::uniform_real_distribution<double > ed(min, max);
return ed(*e__.get());
}
inline std::string sf_random::get_uuid_str()
{
std::uniform_int_distribution<int> ed(INT_MIN, INT_MAX);
int data[4] {ed(*e__.get()), ed(*e__.get()), ed(*e__.get()), ed(*e__.get())};
char c_str[40];
sprintf(c_str,"%0X%0X%0X%0X",data[0],data[1],data[2],data[3]);
std::string ret = c_str;
ret.insert(ret.begin()+20,'-');
ret.insert(ret.begin()+16,'-');
ret.insert(ret.begin()+12,'-');
ret.insert(ret.begin()+8,'-');
return ret;
}
}