由买买提看人间百态

topics

全部话题 - 话题: bigrand
(共0页)
m*****f
发帖数: 1243
1
My shuffle
void Shuffle() {
int n = "size of the deck";
for (int i = n-1; i >= 0; - -i) {
swap(card[i], card[bigrand() % (n- -)]);
}
}
d**e
发帖数: 6098
2
那一页第一行开始就是解释。
由于m<=n,那么总有一个i = n - m,那if里是true,
然后m--,(bigrand()%(n-i) 直到m=0,这时就肯定是输出m个数
s*******n
发帖数: 344
3
c里面没有这个函数啊。
j***y
发帖数: 2074
4
第126页:
The algorithm considers the integers 0, 1, 2, ..., n-1 in order, and selects
each one by appropriate random test. By visiting the integers in order, we
guarantee that the output will be sorted.
To understand the selection criterion, let's consider the example that m=2
and n=5. We should select the first integer 0 with probability 2/5; a
program implements that by a statment like
if (bigrand() % 5) < 2
这里我有点疑问,为什么选第一个数字的时候不是1/5的概率,而是2/5的概率呢?机会
均等地从5个数字中选1个数字,难道概率不应该是1/5吗?
还是我理解的有问题?
(共0页)