Loading... 首先我们需要扩展区间,然后再降维,就可以满足概率分布 扩展区间,调用两个 rand7 就能到 [1,49],为了 [1,10] 我们需要舍去 41-49,剩下的部分进行降维,也就是取余数即可 ```go func rand10() int { for { row := rand7() col := rand7() num := (row - 1) * 7 + col if num > 40 { continue } return (num - 1) % 10 + 1 } } ``` Last modification:July 10, 2025 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏