Skip to content

Commit

Permalink
Merge pull request #40 from JuliaLang/cb/bitrand
Browse files Browse the repository at this point in the history
randbool() -> rand(Bool) and birand()
  • Loading branch information
carlobaldassi committed Jan 8, 2015
2 parents 9401497 + 647acfc commit b84fef9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ if VERSION < v"0.4.0-dev+2056"
end
end

if VERSION < v"0.4.0-dev+2440"
bitrand(r::AbstractRNG, dims::Dims) = rand!(r, BitArray(dims))
bitrand(r::AbstractRNG, dims::Int...) = rand!(r, BitArray(dims))
bitrand(dims::Dims) = rand!(BitArray(dims))
bitrand(dims::Int...) = rand!(BitArray(dims))
export bitrand
Base.rand(::Type{Bool}) = randbool()
end

if VERSION < v"0.4.0-dev+2485"
startswith = Base.beginswith
export startswith
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ end

@test startswith("abcdef","abc") == true
@test startswith("abcdef","def") == false

@test size(bitrand(3, 4)) == (3, 4)
@test size(bitrand((3, 4))) == (3, 4)
@test size(bitrand(MersenneTwister(), 3, 4)) == (3, 4)
@test size(bitrand(MersenneTwister(), (3, 4))) == (3, 4)
@test rand(Bool) in [false, true]

0 comments on commit b84fef9

Please sign in to comment.