@@ -1898,14 +1898,24 @@ function sparse_sortedlinearindices!(I::Vector{Ti}, V::Vector, m::Int, n::Int) w
1898
1898
end
1899
1899
1900
1900
"""
1901
- sprand([rng],[type],m,[n],p::AbstractFloat,[rfn])
1901
+ sprand([rng],[T::Type],m,[n],p::AbstractFloat)
1902
+ sprand([rng],m,[n],p::AbstractFloat,[rfn=rand])
1902
1903
1903
1904
Create a random length `m` sparse vector or `m` by `n` sparse matrix, in
1904
1905
which the probability of any element being nonzero is independently given by
1905
- `p` (and hence the mean density of nonzeros is also exactly `p`). Nonzero
1906
- values are sampled from the distribution specified by `rfn` and have the type `type`. The uniform
1907
- distribution is used in case `rfn` is not specified. The optional `rng`
1908
- argument specifies a random number generator, see [Random Numbers](@ref).
1906
+ `p` (and hence the mean density of nonzeros is also exactly `p`).
1907
+ The optional `rng` argument specifies a random number generator, see [Random Numbers](@ref).
1908
+ The optional `T` argument specifies the element type, which defaults to `Float64`.
1909
+
1910
+ By default, nonzero values are sampled from a uniform distribution using
1911
+ the [`rand`](@ref) function, i.e. by `rand(T)`, or `rand(rng, T)` if `rng`
1912
+ is supplied; for the default `T=Float64`, this corresponds to nonzero values
1913
+ sampled uniformly in `[0,1)`.
1914
+
1915
+ You can sample nonzero values from a different distribution by passing a
1916
+ custom `rfn` function instead of `rand`. This should be a function `rfn(k)`
1917
+ that returns an array of `k` random numbers sampled from the desired distribution;
1918
+ alternatively, if `rng` is supplied, it should instead be a function `rfn(rng, k)`.
1909
1919
1910
1920
# Examples
1911
1921
```jldoctest; setup = :(using Random; Random.seed!(1234))
0 commit comments