diff --git a/base/gmp.jl b/base/gmp.jl index a040d9a2c8c88..46152df8f7513 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -475,6 +475,7 @@ function rand!(r::Range1{BigInt}, A::Array{BigInt}) end rand(r::Range1{BigInt}, dims::Dims) = rand!(r, Array(BigInt, dims)) +rand(r::Range1{BigInt}, dims::Int...) = rand!(r, Array(BigInt, dims...)) function randu(randstate::BigRNG, k::BigInt) z = BigInt() diff --git a/base/mpfr.jl b/base/mpfr.jl index 34213eaef88cc..3264126bde89e 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -19,7 +19,7 @@ import gamma, lgamma, digamma, erf, erfc, zeta, log1p, airyai, iceil, ifloor, itrunc, eps, signbit, sin, cos, tan, sec, csc, cot, acos, asin, atan, cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2, - serialize, deserialize, inf, nan, hash, cbrt, rand, rand! + serialize, deserialize, inf, nan, hash, cbrt, rand, rand!, randn, randn! import Base.Math.lgamma_r @@ -757,4 +757,23 @@ function rand!(r::BigRNG, A::Array{BigFloat}) end rand!(A::Array{BigFloat}) = rand!(Base.GMP.DEFAULT_BIGRNG, A) +function randn(::Type{BigFloat}, randstate::BigRNG) + z = BigFloat() + ccall((:mpfr_grandom,:libmpfr), Int32, + (Ptr{BigFloat}, Ptr{BigFloat}, Ptr{BigRNG}, Int32), + &z, C_NULL, &randstate, ROUNDING_MODE[end]) + z +end +randn(::Type{BigFloat}) = randn(BigFloat, Base.GMP.DEFAULT_BIGRNG) +randn(::Type{BigFloat}, dims::Dims) = randn!(Array(BigFloat, dims)) +randn(::Type{BigFloat}, dims::Int...) = randn!(Array(BigFloat, dims...)) + +function randn!(r::BigRNG, A::Array{BigFloat}) + for i = 1:length(A) + A[i] = randn(BigFloat, r) + end + A +end +randn!(A::Array{BigFloat}) = randn!(Base.GMP.DEFAULT_BIGRNG, A) + end #module