等于接口题。。。随机数生成接口
class Solution {
public:
Solution(vector<int>& w){
if(w.size()) {
int cur = w[0];
pre_sum.push_back(cur);
for(int i = 1; i < w.size(); i++) {
cur += w[i];
pre_sum.push_back(cur);
}
srand((int)time(0));
}
}
int pickIndex() {
// int randv = (dis(mt_rand)+1) % pre_sum.back();
int randv = rand()%pre_sum.back() + 1;
return lower_bound(pre_sum.begin(), pre_sum.end(), randv) - pre_sum.begin();
}
vector<int> pre_sum;
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(w);
* int param_1 = obj->pickIndex();
*/