# Thread: How can i generate random indices of a matrix cell?

1. Member
Join Date
Mar 2013
Posts
11
Rep Power
0

## How can i generate random indices of a matrix cell?

I defined the matrix of int's to be 10 by 10 and i want random position of a cell to be picked starting from index row=5 and cell=0 to row=10 and cell=10 and i want to pick 7 times a cell(a different cell each time) and put in the cell the value of 1(other cells will be zeros).

How can it be done?

2. ## Re: How can i generate random indices of a matrix cell?

I think it would be easier if you define a "row range" and a "cell range", and that would define a "block" of cells that fall within that given zone.

Then, you could generate 2 random numbers, R and C, that are locked into the "row range" and "cell range", respectively.

3. ## Re: How can i generate random indices of a matrix cell?

Define a class Point (x,y) or use an existing class and stick all points that can possibly be selected in a Collection like a List, call Collections.shuffle(yourCollection) and finally use the first seven Points from your Collection. Alternatively select a random point and check if it is already selected before, if not, definitely select it and stick the Point in the 'taboo' List or Set or whatever.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•