vendredi 7 mai 2021

select nodes randomly java

I have an array list that looks like this.

8.1,6.5,4.4,3.2,1,8.9,5,1.4,0.1,1,8.7,6.2,4.3,3.2,3

every 5 nodes are a node I need the program to select random nodes

for example to select

8.1,6.5,4.4,3.2,1,8.7,6.2,4.3,3.2,3

as you can see it selected 5 numbers from the begging and 5 more from the end

and saves them


Random random_method = new Random();

// loop for generation random number
for (int i = 0; i < array.size(); i++) 
{
    // generating random index with the help of
    // nextInt() method
    int index = random_method.nextInt(array.size());

    System.out.println("Random Element is :" + array.get(index));

}





I have this but that not doing what I need




Aucun commentaire:

Enregistrer un commentaire