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?
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.
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