Skip to content

Commit

Permalink
rand! for typed arrays – pass the element type to scalar rand call.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Oct 25, 2014
1 parent 2cddef3 commit 89befaf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ rand(r::AbstractRNG, dims::Dims) = rand!(r, Array(Float64, dims))
rand(r::AbstractRNG, dims::Int...) = rand(r, dims)

function rand!{T}(A::Array{T})
for i=1:length(A)
for i = 1:length(A)
A[i] = rand(T)
end
A
end

function rand!(r::AbstractRNG, A::AbstractArray)
for i=1:length(A)
@inbounds A[i] = rand(r)
function rand!{T}(r::AbstractRNG, A::AbstractArray{T})
for i = 1:length(A)
@inbounds A[i] = rand(r, T)
end
A
end
Expand Down

0 comments on commit 89befaf

Please sign in to comment.