Redian新闻
>
help understanding code (random number)
avatar
help understanding code (random number)# Programming - 葵花宝典
c*t
1
Hi, this is copy&paste from a piece of code I am reading, but
can't understand:
int nc[5], extObt = 0;
set freeNumbers;
......
set::iterator si;
for (si = freeNumbers.begin(); si != freeNumbers.end() && extObt < 5;
++si)
{
if ((*si) % 200 == (rand() % 82))
{
nc[extObt] = (*si);
extObt++;
}
}
The funciton of the code is to randomly pick up 5 numbers from the set
of freeNumbers, but I can't understand how it i
avatar
c*t
2
someone help? the number 200 and 82 come out of nowhere.
I guess it's something to do with math, but my math is to
bad to tell.

【在 c*****t 的大作中提到】
: Hi, this is copy&paste from a piece of code I am reading, but
: can't understand:
: int nc[5], extObt = 0;
: set freeNumbers;
: ......
: set::iterator si;
: for (si = freeNumbers.begin(); si != freeNumbers.end() && extObt < 5;
: ++si)
: {
: if ((*si) % 200 == (rand() % 82))

avatar
h*o
3
freeNumbers里都是些什么呀?
感觉是在模拟什么随机过程,(*si)%200 > 81的永远不会被选中
(*si)%200 <= 81的有1/82的几率被选中

【在 c*****t 的大作中提到】
: Hi, this is copy&paste from a piece of code I am reading, but
: can't understand:
: int nc[5], extObt = 0;
: set freeNumbers;
: ......
: set::iterator si;
: for (si = freeNumbers.begin(); si != freeNumbers.end() && extObt < 5;
: ++si)
: {
: if ((*si) % 200 == (rand() % 82))

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。