How to create a sparse matrix obeying (-1,1) uniform distribution

I try to code

using SparseArrays
using Distributions
sprandn(100,100,0.3,Uniform(-1,1))

But it failed. So how to generate a sparse matrix obeying (-1,1) uniform distribution? Thanks

You need sprand rather than sprandn, and the last argument should be a function that maps n to a vector of n samples (though the docs don’t seem to say so anywhere).

sprand(100,100,0.1,n->rand(Uniform(-1,1),n))