a little bit off, 5f+f has 25 possiblities, need to remove 1
【在 g*****i 的大作中提到】 : 好像经典书里有,答案是不是(f()*5+f())%8+1
p*y
18 楼
恩,f()*5+f()以后remove 6 or 30就行了
【在 t******h 的大作中提到】 : a little bit off, 5f+f has 25 possiblities, need to remove 1
t*h
19 楼
yeah saw another funny solution today, having a 5x5 matrix fillup with (1-8)* 3times, 0*1time then r1_8=0 while (r1_8==0) r1_8 = matrix[rand(5)-1][rand(5)-1];
【在 p*****y 的大作中提到】 : 恩,f()*5+f()以后remove 6 or 30就行了
g*i
20 楼
原来如此,只要生成的不是目标的公倍数,就要检查下头尾,去掉一些余数一样的.
【在 t******h 的大作中提到】 : a little bit off, 5f+f has 25 possiblities, need to remove 1
good point. how about this: int rand1() { int i = (f() - 1)/ 2; if (i > 1) return rand1(); return i; } rand8 = rand1() + rand1() + ... + rand1() seven times + 1
【在 t******h 的大作中提到】 : check my previous post, f()+f() eight times is NOT evenly distributed : you can use 7*f()+f()...