-
Notifications
You must be signed in to change notification settings - Fork 0
/
picker.h
46 lines (35 loc) · 1.19 KB
/
picker.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
// by wuwbobo2021 <https://github.com/wuwbobo2021>, <wuwbobo@outlook.com>
// If you have found bugs in this program, please pull an issue, or contact me.
#ifndef RAMDOM_PICKER_PICKER_H
#define RAMDOM_PICKER_PICKER_H
#include "table.h"
#include <random>
namespace RandomPicker
{
class Picker
{
Table& m_table;
std::vector<double> m_grid;
std::vector<char> m_vect_picked; //bool. char is used to avoid the specific implementation of vector<bool>.
std::random_device m_ran_dev;
bool m_flag_testing = false;
double random_value(double width); //0.0 ~ width
void draw(); //draw the grid for all items in the table
unsigned int determine(double val) const;
public:
Picker(Table& table);
void pick(unsigned int amount, std::vector<unsigned int>& result);
void pick(unsigned int amount, std::vector<std::string>& result);
void test(unsigned int times, unsigned int amount, Table& result);
void calculate(unsigned int pick_amount, Table& result) const;
};
inline Picker::Picker(Table& table):
m_table(table)
{}
inline double Picker::random_value(double width)
{
unsigned int val = m_ran_dev();
return width * (double)(val - m_ran_dev.min()) / (double)(m_ran_dev.max() - m_ran_dev.min());
}
}
#endif