What am doing wrong here in this piece of code ? What is a better way to generate N digit random number ?
public static boolean isPrime(long n){
return (Math.pow(2, n-1) % n == 1) && (Math.pow(3, n-1) % n == 1);
}
public static long getPrime(int digit){
long sample;
long multiple = Math.round(Math.pow(10, digit));
do{
sample = Math.round(Math.random()* multiple);
//System.out.println(sample);
}while(!isPrime(sample));
return sample;
}
Aucun commentaire:
Enregistrer un commentaire