Insert n points of a vector randomly into any matrix in java

Asked

Viewed 79 times

-2

I’m beginner in java, I was wondering if there is any function that would facilitate my life so that:

having a vector of n positions filled with (pre-defined) numbers, distribute these numbers at the positions of a matrix randomly.

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

Grateful.

1 answer

1


There is no need for any library for such a simple task, perhaps just the Random to give you the random positions.

Example:

Random random = new Random();
matriz[random.nextInt(15)][random.nextInt(10)] = vetor[i];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.