C语言 | Leetcode C语言题解之第470题用Rand7()实现Rand10()
题目:
题解:
// The rand7() API is already defined for you.
// int rand7();
// @return a random integer in the range 1 to 7int rand10() {while(true) {int index = (rand7() - 1) * 7 + rand7(); if(index <= 40) return index % 10 + 1; }
}