MCPcopy Create free account
hub / github.com/careercup/ctci / rand7

Method rand7

java/Chapter 17/Question17_11/Question.java:4–11  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3public class Question {
4 public static int rand7() {
5 while (true) {
6 int num = 5 * rand5() + rand5();
7 if (num < 21) {
8 return num % 7;
9 }
10 }
11 }
12
13 public static int rand5() {
14 return (int) (Math.random() * 100) % 5;

Callers 1

mainMethod · 0.95

Calls 1

rand5Method · 0.95

Tested by

no test coverage detected