Insert n points of a vector randomly into any array in java [closed]

-2

I am a beginner in Java, I wanted to know if there is any function that would make my life easier:

Having a vector of n positions filled with (pre-defined) numbers, distribute those numbers in randomly array positions.

For example: having a 10-position vector with 10 numbers and a 15x10 matrix, distribute those 10 numbers randomly in the matrix positions, in which case the position that eventually is not filled would have no problems.

Thank you.

    
asked by anonymous 28.08.2018 / 04:09

1 answer

1

There's no need for any library for this simple task, maybe just Random to give you the random positions.

Example:

Random random = new Random();
matriz[random.nextInt(15)][random.nextInt(10)] = vetor[i];
    
28.08.2018 / 13:46