Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Random rand = new Random();
- private final int[] primes = calcPrimes(DIM, DIM);
- @Override
- public int hashCode(){
- int result = 1;
- for(int i = 0; i < DIM; i++){
- for(int j = 0; j < DIM; j++){
- result += (tabla[i][j] + 3) * primes[i + j];
- }
- }
- return result;
- }
- private int[] calcPrimes(int d1, int d2){
- final int d = d1 * d2;
- int[] result = new int[d];
- for(int i = 0; i < d; i++){
- //Increasing the value(to some number)
- //will improve in results
- result[i] = getPrime(50);
- }
- return result;
- }
- private int getPrime(int t){
- int result = 1;
- while(true){
- int r = rand.nextInt(t);
- if(isPrime(r)){
- return r;
- }
- }
- }
- public static boolean isPrime(int n){
- for(int i = 2; i < n; i++){
- if(n % i == 0){
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement