lundi 12 avril 2021

How to make a random super increasing array

I'm having a lab about making a Merkle Hellman Knapsack,the request said i need to make an automatically super increasing array but i don't know how to make it,is there any way to make it ? Thanks for reading

Random random = new Random();
int[] wInt =  random.ints(8,1,999).toArray();
              for(int i = 0; i<8-1; i++) {
     for (int j = i+1; j<wInt.length; j++) {
        if(wInt[i] > wInt[j]) {
           int temp = wInt[i];
           wInt[i] = wInt[j];
           wInt[j] = temp;
        }
     }
  }        



Aucun commentaire:

Enregistrer un commentaire