Skip to content

Commit 5e019eb

Browse files
author
Aleksandr Pronichev
committed
update
1 parent f8be073 commit 5e019eb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

app/src/main/java/hexlet/code/games/GCD.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package hexlet.code.games;
22

33
import hexlet.code.Engine;
4+
import hexlet.code.Utils;
45

56
public class GCD {
67

78
private static final String RULES = "Find the greatest common divisor of given numbers.";
89
private static final int MAX_NUMBER = 100;
10+
private static final int MIN_NUMBER = 1;
911

1012
public static void gameGCD() {
1113
String[][] questionsAndAnswers = generateData();
@@ -16,8 +18,8 @@ public static String[][] generateData() {
1618
String[][] questionsAndAnswers = new String[Engine.ROUNDS][2];
1719

1820
for (int i = 0; i < Engine.ROUNDS; i++) {
19-
int firstNumber = (int) (Math.random() * MAX_NUMBER);
20-
int secondNumber = (int) (Math.random() * MAX_NUMBER);
21+
int firstNumber = Utils.getRandomInt(MIN_NUMBER, MAX_NUMBER);
22+
int secondNumber = Utils.getRandomInt(MIN_NUMBER, MAX_NUMBER);
2123
String question = firstNumber + " " + secondNumber;
2224

2325
int gcd = calculateGCD(firstNumber, secondNumber);

app/src/main/java/hexlet/code/games/Prime.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package hexlet.code.games;
22

33
import hexlet.code.Engine;
4+
import hexlet.code.Utils;
45

56
public class Prime {
67

78
private static final String RULES = "Answer 'yes' if given number is prime. Otherwise answer 'no'.";
89
private static final int MAX_NUMBER = 100;
10+
private static final int MIN_NUMBER = 1;
911

1012
public static void gamePrime() {
1113
String[][] questionsAndAnswers = generateData();
@@ -16,7 +18,7 @@ public static String[][] generateData() {
1618
String[][] questionsAndAnswers = new String[Engine.ROUNDS][2];
1719

1820
for (int i = 0; i < Engine.ROUNDS; i++) {
19-
int number = (int) (Math.random() * MAX_NUMBER);
21+
int number = Utils.getRandomInt(MIN_NUMBER, MAX_NUMBER);
2022
questionsAndAnswers[i][0] = Integer.toString(number);
2123
if (isPrime(number)) {
2224
questionsAndAnswers[i][1] = "yes";

0 commit comments

Comments
 (0)