Skip to content

Commit d1b193c

Browse files
committed
add missing rand function for Char's
1 parent 0398bb2 commit d1b193c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

base/random.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ end
246246
rand(r::MersenneTwister, ::Type{Int64}) = reinterpret(Int64, rand(r, UInt64))
247247
rand(r::MersenneTwister, ::Type{Int128}) = reinterpret(Int128, rand(r, UInt128))
248248

249-
## random complex values
249+
## random Complex values
250250

251251
rand{T<:Real}(r::AbstractRNG, ::Type{Complex{T}}) = complex(rand(r, T), rand(r, T))
252252

253+
## random Char values
254+
rand(r::AbstractRNG, ::Type{Char}) = Char(rand(r, UInt32))
255+
253256
## Arrays of random numbers
254257

255258
rand(r::AbstractRNG, dims::Dims) = rand(r, Float64, dims)

test/random.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ srand(0); rand(); x = rand(384);
88
@test -10 <= rand(-10:-5) <= -5
99
@test -10 <= rand(-10:5) <= 5
1010
@test minimum([rand(Int32(1):Int32(7^7)) for i = 1:100000]) > 0
11-
@test(typeof(rand(false:true)) == Bool)
12-
11+
@test typeof(rand(false:true)) == Bool
12+
@test typeof(rand(Char)) == Char
1313
@test length(randn(4, 5)) == 20
1414
@test length(bitrand(4, 5)) == 20
1515

@@ -290,7 +290,7 @@ for rng in ([], [MersenneTwister()], [RandomDevice()])
290290
rand!(rng..., BitArray(5)) ::BitArray{1}
291291
rand!(rng..., BitArray(2, 3)) ::BitArray{2}
292292

293-
for T in [Base.IntTypes..., Bool, Float16, Float32, Float64]
293+
for T in [Base.IntTypes..., Bool, Char, Float16, Float32, Float64]
294294
a0 = rand(rng..., T) ::T
295295
a1 = rand(rng..., T, 5) ::Vector{T}
296296
a2 = rand(rng..., T, 2, 3) ::Array{T, 2}

0 commit comments

Comments
 (0)