I have the foll0wing code to generate a matrix of 0’s and 1’s using java.util.Random and a 2d array. I was wondering if there is a way to define the probability of the number of 0’s and 1’s occurring per row in the matrix. I want to have an equal probability of generating both 0’s and 1’s.
I want to convert this matlab equivalent code to generate a matrix into the java equivalent.
G= rand(10,20)<.5
Any ideas or suggestions?
Thanks,
Bhavya
There is no predefined method for filling your array with numbers, but instead you need to do lop over each element and assign it the number. Something like this:
This assumes that the default random generator is good enough. Adjust the 0.5 if you want higher probability for 1s or 0s.