Skip to content

Commit

Permalink
remove rand!(::AbstractArray, ::AbstractArray) until #8246 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Sep 17, 2014
1 parent 4bbe115 commit 91b58f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,18 @@ rand(r::AbstractArray) = r[rand(randintgen(length(r)))]

# Arrays of random integers

function rand!(r::AbstractArray, A::AbstractArray)
rand!(r::Range, A::AbstractArray) = rand!(r, A, ())

# TODO: this more general version is "disabled" until #8246 is resolved
function rand!(r::AbstractArray, A::AbstractArray, ::())
g = randintgen(length(r))
for i = 1 : length(A)
@inbounds A[i] = r[rand(g)]
end
return A
end

rand{T}(r::AbstractArray{T}, dims::Dims) = rand!(r, Array(T, dims))
rand{T}(r::AbstractArray{T}, dims::Dims) = rand!(r, Array(T, dims), ())
rand(r::AbstractArray, dims::Int...) = rand(r, dims)


Expand Down
4 changes: 2 additions & 2 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3964,9 +3964,9 @@ Random number generation in Julia uses the `Mersenne Twister library <http://www

Pick a random element or array of random elements from the indexable collection ``coll`` (for example, ``1:n`` or ``['x','y','z']``).

.. function:: rand!(coll, A)
.. function:: rand!(r, A)

Populate the array A with random values drawn uniformly from the indexable collection ``coll``.
Populate the array A with random values drawn uniformly from the range ``r``.

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

Expand Down
2 changes: 1 addition & 1 deletion test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ rand!(MersenneTwister(0), A)
@test rand(0:3:1000) in 0:3:1000
coll = {2, uint128(128), big(619), "string", 'c'}
@test rand(coll) in coll
@test issubset(rand!(coll, cell(10)), coll)
@test issubset(rand(coll, 2, 3), coll)

# randn
@test randn(MersenneTwister(42)) == -0.5560268761463861
Expand Down

0 comments on commit 91b58f7

Please sign in to comment.