Results 1 to 3 of 3
- 03-08-2013, 05:13 PM #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?
- 03-08-2013, 05:47 PM #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.
- 03-08-2013, 05:48 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
to generate random lottery no
By fakepics500 in forum New To JavaReplies: 19Last Post: 07-08-2011, 09:14 AM -
[Q] Generate Random Letter
By iriscience in forum New To JavaReplies: 11Last Post: 01-31-2011, 12:10 AM -
Random integer generate
By trbLeeciN in forum New To JavaReplies: 6Last Post: 06-22-2010, 01:19 AM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 05:50 PM -
Trying to Generate Random number
By PeterFeng in forum New To JavaReplies: 10Last Post: 01-14-2009, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks