I don't know how big your matrices are and how you organized your loops,
but I would try the following (written without checking in GAP, so be
# assuming that n1, n2 and w (integers) are given
f := GF(2); matrix := NullMat(n1, n2, f); # not sure if this is syntax for null matrix # over f, check manual for k in [1..w] do i := Random([1..n1]); j := Random([1..n2]); matrix[i][j] := One(f); od;
This should run reasonably fast; the expected weight of the matrix is
slightly smaller than the given parameter w, however the error is small
for small weights (quadratic in w/(n1*n2)?).
Hope this helps.
Dept. of Math. Sci.
University of Delaware