-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigNumberGenerator.java
55 lines (48 loc) · 1.56 KB
/
BigNumberGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package bignumber_generator;
import java.math.BigInteger;
import java.util.Random;
/**
* This class is responsible for generating random numbers
*/
public class BigNumberGenerator {
public BigNumberGenerator(){
}
/**
* Generates a probably big prime integer with specific bit numbers
* @param bitsNumber
* @return the big prime integers
*/
public BigInteger generateBigPrimeIntegersWithNumberOfBits(int bitsNumber){
boolean isPrimeNumberGenerated = false;
BigInteger primeNum_p = BigInteger.ZERO;
while (!isPrimeNumberGenerated){
Random rnd = new Random();
BigInteger primeNumCandidate = new BigInteger(bitsNumber, rnd);
if (primeNumCandidate.isProbablePrime(1)){
primeNum_p = primeNumCandidate;
isPrimeNumberGenerated = true;
}
}
return primeNum_p;
}
/**
* Generates a big integer with specific bit numbers
* @param bitsNumber
* @return the big integer
*/
public BigInteger generateBigIntegersWithNumberOfBits(int bitsNumber){
Random rnd = new Random();
BigInteger bigInteger = new BigInteger(bitsNumber, rnd);
return bigInteger;
}
// public BigInteger bigIntInRange(BigInteger min, BigInteger max){
// Random rnd = new Random();
//
// BigInteger x = new BigInteger(max.bitLength(), rnd);
//
// while (x.compareTo(min) <= 0 || x.compareTo(max) >= 0){
// x = new BigInteger(max.bitLength(), rnd);
// }
// return x;
// }
}