已知一个函数rand7()能够生成1-7的随机数，请给出一个函数rand10()，该函数能够生成1-10的随机数。

   1  2  3  4  5  6  7
1  1  2  3  4  5  6  7
2  8  9 10  1  2  3  4
3  5  6  7  8  9 10  1
4  2  3  4  5  6  7  8
5  9 10  1  2  3  4  5
6  6  7  8  9 10  *  *
7  *  *  *  *  *  *  *

int rand10() {
int row, col, idx;
do {
row = rand7();
col = rand7();
idx = col + (row-1)*7;
} while (idx > 40);
return 1 + (idx-1)%10;
}

E(# calls to rand7) = 2 * (40/49) +
4 * (9/49) * (40/49) +
6 * (9/49)2 * (40/49) +
...

∞
= ∑ 2k * (9/49)k-1 * (40/49)
k=1

= (80/49) / (1 - 9/49)2
= 2.45

int rand10Imp() {
int a, b, idx;
while (true) {
a = rand7();
b = rand7();
idx = b + (a-1)*7;
if (idx <= 40)
return 1 + (idx-1)%10;
a = idx-40;
b = rand7();
// get uniform dist from 1 - 63
idx = b + (a-1)*7;
if (idx <= 60)
return 1 + (idx-1)%10;
a = idx-60;
b = rand7();
// get uniform dist from 1-21
idx = b + (a-1)*7;
if (idx <= 20)
return 1 + (idx-1)%10;
}
}

E(# calls to rand7) = 2 * (40/49) +
3 * (9/49) * (60/63) +
4 * (9/49) * (3/63) * (20/21) +

(9/49) * (3/63) * (1/21) *
[ 6 * (40/49) +
7 * (9/49) * (60/63) +
8 * (9/49) * (3/63) * (20/21) ] +

((9/49) * (3/63) * (1/21))2 *
[ 10 * (40/49) +
11 * (9/49) * (60/63) +
12 * (9/49) * (3/63) * (20/21) ] +
...

= 2.2123