@@ -41,6 +41,16 @@ is omitted). For example, `rand(make(Array, 2, 3), 3)` creates an array of matri
4141Of course, ` make ` is not necessary, in that the same can be achieved with an ad hoc ` struct ` ,
4242which in some cases is clearer (e.g. ` Normal(m, s) ` rather than something like ` make(Float64, Val(:Normal), m, s) ` ).
4343
44+ As an experimental feature, the following alternative API is available:
45+ - ` rand(T => x) ` is equivalent to ` rand(make(T, x)) `
46+ - ` rand(T => (x, y, ...)) ` is equivalent to ` rand(make(T, x, y, ...)) `
47+
48+ This is for convenience only (it may be more readable), but may be less efficient due to the
49+ fact that the type of a pair containing a type doesn't know this exact type (e.g. ` Pair => Int `
50+ has type ` Pair{UnionAll,DataType} ` ), so ` rand ` can't infer the type of the generated value.
51+ Thanks to inlining, the inferred types can however be sufficiently tight in some cases
52+ (e.g. ` rand(Complex => Int, 3) ` is of type ` Vector{Complex{Int64}} ` instead of ` Vector{Any} ` ).
53+
4454Point 3) allows something like ` rand(1:30, Set, 10) ` to produce a ` Set ` of length ` 10 ` with values
4555from ` 1:30 ` . The idea is that ` rand([rng], [S], Cont, etc...) ` should always be equivalent to
4656` rand([rng], make(Cont, [S], etc...)) ` . This design goes somewhat against the trend in ` Base ` to create
@@ -204,6 +214,12 @@ julia> collect(Iterators.take(Uniform(1:10), 3)) # distributions can be iterated
204214 7
205215 10
206216 5
217+
218+ julia> rand (Complex => Int) # equivalent to rand(make(Complex, Int)) (experimental)
219+ 4610038282330316390 + 4899086469899572461im
220+
221+ julia> rand (Pair => (String, Int8)) # equivalent to rand(make(Pair, String, Int8)) (experimental)
222+ " ODNXIePK" => 4
207223```
208224
209225In some cases, the ` Rand ` iterator can provide efficiency gains compared to
0 commit comments