Skip to content

Commit 9d0282e

Browse files
committed
update the docs for rand/rand! and add some related tests
1 parent 6d329ce commit 9d0282e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

doc/stdlib/base.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -3946,7 +3946,7 @@ Random number generation in Julia uses the `Mersenne Twister library <http://www
39463946

39473947
.. function:: rand!([rng], A)
39483948

3949-
Populate the array A with random number generated from the specified RNG.
3949+
Populate the array A with random numbers generated from the specified RNG.
39503950

39513951
.. function:: rand(rng::AbstractRNG, [dims...])
39523952

@@ -3960,9 +3960,13 @@ Random number generation in Julia uses the `Mersenne Twister library <http://www
39603960

39613961
Generate a random number or array of random numbes of the given type.
39623962

3963-
.. function:: rand(r, [dims...])
3963+
.. function:: rand(coll, [dims...])
39643964

3965-
Pick a random element or array of random elements from range ``r`` (for example, ``1:n`` or ``0:2:10``).
3965+
Pick a random element or array of random elements from the indexable collection ``coll`` (for example, ``1:n`` or ``['x','y','z']``).
3966+
3967+
.. function:: rand!(coll, A)
3968+
3969+
Populate the array A with random values drawn uniformly from the indexable collection ``coll``.
39663970

39673971
.. function:: randbool([dims...])
39683972

test/random.jl

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ rand!(MersenneTwister(0), A)
2626
@test A == [0.8236475079774124 0.16456579813368521;
2727
0.9103565379264364 0.17732884646626457]
2828

29+
@test rand(0:3:1000) in 0:3:1000
30+
coll = {2, uint128(128), big(619), "string", 'c'}
31+
@test rand(coll) in coll
32+
@test issubset(rand!(coll, cell(10)), coll)
33+
2934
# randn
3035
@test randn(MersenneTwister(42)) == -0.5560268761463861
3136
A = zeros(2, 2)

0 commit comments

Comments
 (0)