-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathOldMask.h
76 lines (64 loc) · 1.39 KB
/
OldMask.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @file Mask.h
* @brief 彩色二维码旧版掩码
*/
#pragma once
class COldMask
{
public:
/**
* @brief 构造一个旧的掩码
* @param[in] nMin 随机数最小值
* @param[in] nMax 随机数最大值
* @param[in] nSeed 随机数种子
* @note 旧的掩码是产生随机数,填补多余的模块
*/
COldMask(int nMin, int nMax, unsigned int nSeed)
: m_nMin(nMin), m_nMax(nMax), m_nSeed(nSeed), m_pMaskData(0), m_nMaskNum(0), m_nIndex(0) { }
~COldMask() { SAFE_DELETE(m_pMaskData); }
// 随机产生nNums个不同的整数,介于nMin到nMax
void GenerateInterferenceData(int nNums, int nMaskingNo = 0, int nVersion = 0);
/// 是否是干扰信息
inline bool IsMasked(int &k)
{
if (k == m_pMaskData[m_nIndex] && m_nIndex < m_nMaskNum)
{
k++;
m_nIndex++;
return true;
}
return false;
}
private:
/** 随机数最小值 */
int m_nMin;
/** 随机数最大值 */
int m_nMax;
/** 随机数种子 */
unsigned int m_nSeed;
/** 随机数发生器的默认种子 */
static unsigned int ___next;
/// 掩码数据
int *m_pMaskData;
/// 掩码个数
int m_nMaskNum;
/// 下标
int m_nIndex;
/**
* @brief rand在windows和android下产生的随机数列不一样的解决办法
* @see http://blog.csdn.net/zhch152/article/details/47862853
* @date 2015-08-22 20:08
*/
inline int my_rand()
{
___next = ___next * 0x343fd + 0x269EC3;
return (___next >> 0x10) & 0x7FFF;
}
/**
* @brief 设置随机数发生器的种子
*/
inline void my_srand(unsigned int ___seed)
{
___next = ___seed;
}
};