how-to

Math

How to generate prime number

For prime generating you can use class java.math.BigInteger. First parameter is bit length of prime, second is random generator.

/* -- using of BigInteger - how to generate primes */
       
BigInteger prime = BigInteger.probablePrime( 8, new Random() );
System.out.println( prime.intValue() );

Output could be:

139