Tuesday, January 24, 2012

How to generate a random prime number in java

Consider the following program

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
public class RandomPrime
    {
    public static void main(String arg[])
        {
            Random ran = new SecureRandom();
            System.out.println(BigInteger.probablePrime(10, ran));
            }
    }

This program will generate a prime number randomly using the built-in function.
Save the program as RandomPrime.java

1 comment :

  1. Las Vegas Casinos - Mapyro
    Find 실시간 바카라 사이트 미니미닝 the BEST and NEWEST Casinos in Las Vegas, 울산광역 출장샵 NV. 서산 출장샵 We compare the 이천 출장안마 safety, security and reputation of all our Las 경주 출장마사지 Vegas casinos.

    ReplyDelete