How about this:

julia> cs = collect(2:N); i = 1;

julia> N=5; k=2; I = Array(Int, N*k); J = Array(Int, N*k); V = fill(true, 
N*k);

julia> for r in 1:N
           rng = (r-1)*k+1 : r*k
           I[rng] = r
           J[rng] = sample(cs, k; replace=false)
           if r<N
               cs[r] -= 1
           end
       end

julia> spmat = sparse(I, J, V, N, N)
5x5 sparse matrix with 10 Bool entries:
        [2, 1]  =  true
        [3, 1]  =  true
        [5, 1]  =  true
        [1, 2]  =  true
        [4, 2]  =  true
        [5, 2]  =  true
        [2, 3]  =  true
        [4, 3]  =  true
        [3, 4]  =  true
        [1, 5]  =  true

julia> full(spmat)
5x5 Array{Bool,2}:
 false   true  false  false   true
  true  false   true  false  false
  true  false  false   true  false
 false   true   true  false  false
  true   true  false  false  false




On Thursday, July 23, 2015 at 2:29:36 PM UTC-4, Seth wrote:
>
> Hi all,
>
> I'm looking for really clever (FAST) ways of creating an NxN sparse random 
> boolean matrix that has the following properties:
>
> * exactly k (k <= N) true values per row, and
> * no true values on the diagonal (mx[i,i]).
>
> Anyone have an ingenious way of creating something like this?
>

Reply via email to