diff --git a/base/exports.jl b/base/exports.jl index 64768f49bd8ff..8db5bc040691e 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -22,7 +22,6 @@ export Bidiagonal, BigFloat, BigInt, - BigRNG, BitArray, BitMatrix, BitVector, diff --git a/base/gmp.jl b/base/gmp.jl index 88671b75f2826..98f8f5f549bcd 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -1,13 +1,13 @@ module GMP -export BigInt, BigRNG +export BigInt import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($), binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, isprime, powermod, widemul, sum, trailing_zeros, trailing_ones, count_ones, base, parseint, serialize, deserialize, bin, oct, dec, hex, isequal, invmod, - prevpow2, nextpow2, ndigits0z, rand, rand!, srand + prevpow2, nextpow2, ndigits0z type BigInt <: Integer alloc::Cint @@ -419,87 +419,4 @@ widemul{T<:Integer}(x::T, y::T) = BigInt(x)*BigInt(y) prevpow2(x::BigInt) = x < 0 ? -prevpow2(-x) : (x <= 2 ? x : one(BigInt) << (ndigits(x, 2)-1)) nextpow2(x::BigInt) = x < 0 ? -nextpow2(-x) : (x <= 2 ? x : one(BigInt) << ndigits(x-1, 2)) -# Random number generation -type BigRNG <: AbstractRNG - seed_alloc::Cint - seed_size::Cint - seed_d::Ptr{Void} - alg::Cint - alg_data::Ptr{Void} - - function BigRNG() - randstate = new(zero(Cint), zero(Cint), C_NULL, zero(Cint), C_NULL) - # The default algorithm in GMP is currently MersenneTwister - ccall((:__gmp_randinit_default, :libgmp), Void, (Ptr{BigRNG},), - &randstate) - finalizer(randstate, BigRNG_clear) - randstate - end -end - -# Initialize with seed -function BigRNG(seed::Uint64) - randstate = BigRNG() - ccall((:__gmp_randseed_ui, :libgmp), Void, (Ptr{BigRNG}, Culong), - &randstate, seed) - randstate -end -function BigRNG(seed::BigInt) - randstate = BigRNG() - ccall((:__gmp_randseed, :libgmp), Void, (Ptr{BigRNG}, Ptr{BigInt}), - &randstate, &seed) - randstate -end - -function BigRNG_clear(x::BigRNG) - ccall((:__gmp_randclear, :libgmp), Void, (Ptr{BigRNG},), &x) -end - -function rand(::Type{BigInt}, randstate::BigRNG, n::Integer) - m = convert(BigInt, n) - randu(randstate, m) -end - -function rand(r::Range1{BigInt}) - ulen = convert(BigInt, length(r)) - convert(BigInt, first(r) + randu(ulen)) -end - -function rand!(r::Range1{BigInt}, A::Array{BigInt}) - for i = 1:length(A) - A[i] = rand(r) - end - A -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() - ccall((:__gmpz_urandomm, :libgmp), Void, - (Ptr{BigInt}, Ptr{BigRNG}, Ptr{BigInt}), &z, &randstate, &k) - z -end -randu(k::BigInt) = randu(Base.Random.DEFAULT_BIGRNG, k) - -srand(r::BigRNG, seed) = srand(r, convert(BigInt, seed)) -function srand(randstate::BigRNG, seed::Vector{Uint32}) - s = big(0) - for i in seed - s = s << 32 + i - end - srand(randstate, s) -end -function srand(randstate::BigRNG, seed::Uint64) - ccall((:__gmp_randseed_ui, :libgmp), Void, (Ptr{BigRNG}, Culong), - &randstate, seed) - return -end -function srand(randstate::BigRNG, seed::BigInt) - ccall((:__gmp_randseed, :libgmp), Void, (Ptr{BigRNG}, Ptr{BigInt}), - &randstate, &seed) - return -end - end # module diff --git a/base/mpfr.jl b/base/mpfr.jl index 8432f5412b7d8..c4302627803ea 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -17,8 +17,7 @@ import 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, typemax, typemin, - realmin, realmax, get_rounding, set_rounding, - rand, rand!, randn, randn! + realmin, realmax, get_rounding, set_rounding import Base.Math.lgamma_r @@ -733,41 +732,4 @@ function hash(x::BigFloat) h end -# RNG-related functions -function rand(::Type{BigFloat}, randstate::BigRNG) - z = BigFloat() - ccall((:mpfr_urandom,:libmpfr), Int32, - (Ptr{BigFloat}, Ptr{BigRNG}, Int32), - &z, &randstate, ROUNDING_MODE[end]) - z -end -rand(::Type{BigFloat}) = rand(BigFloat, Base.Random.DEFAULT_BIGRNG) - -function rand!(r::BigRNG, A::Array{BigFloat}) - for i = 1:length(A) - A[i] = rand(BigFloat, r) - end - A -end -rand!(A::Array{BigFloat}) = rand!(Base.Random.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.Random.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.Random.DEFAULT_BIGRNG, A) - end #module diff --git a/base/random.jl b/base/random.jl index 62d44263700d6..b4885d3f315c5 100644 --- a/base/random.jl +++ b/base/random.jl @@ -54,8 +54,7 @@ function librandom_init() seed = reinterpret(Uint64, time()) seed = bitmix(seed, uint64(getpid())) try - @linux_only seed = bitmix(seed, parseint(Uint64, readall(`ifconfig` |> `sha1sum`)[1:40], 16)) - @osx_only seed = bitmix(seed, parseint(Uint64, readall(`ifconfig` |> `shasum`)[1:40], 16)) + seed = bitmix(seed, parseint(Uint64, readall(`ifconfig` |> `sha1sum`)[1:40], 16)) catch # ignore end @@ -76,12 +75,6 @@ end function srand(seed::Vector{Uint32}) global RANDOM_SEED = seed dsfmt_gv_init_by_array(seed) - s = big(0) - for i in Base.Random.RANDOM_SEED - s = s << 32 + i - end - global DEFAULT_BIGRNG = BigRNG(s) - return end srand(n::Integer) = srand(make_seed(n)) diff --git a/doc/helpdb.jl b/doc/helpdb.jl index 5e09f974babee..b34cf05bc2bb7 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -4830,8 +4830,7 @@ popdisplay(d::Display) Seed the RNG with a \"seed\", which may be an unsigned integer or a vector of unsigned integers. \"seed\" can even be a filename, in which case the seed is read from a file. If the argument \"rng\" is - not provided, the default global RNG and the default BigRNG are - seeded. + not provided, the default global RNG is seeded. "), @@ -4843,24 +4842,9 @@ popdisplay(d::Display) "), -("Random Numbers","Base","BigRNG","BigRNG([seed]) - - Create a \"BigRNG\" RNG object, used exclusively to generate random - BigInts and BigFloats. Different RNG objects can have their own - seeds, which may be useful for generating different streams of - random numbers. - -"), - ("Random Numbers","Base","rand","rand() - Generate a \"Float64\" random number uniformly in [0,1). - -"), - -("Random Numbers","Base","rand","rand(BigFloat) - - Generate a \"BigFloat\" random number uniformly in [0,1). + Generate a \"Float64\" random number uniformly in [0,1) "), @@ -4880,24 +4864,9 @@ popdisplay(d::Display) "), -("Random Numbers","Base","rand","rand(BigFloat, rng::AbstractRNG[, dims...]) - - Generate a random \"BigFloat\" number or array of the size - specified by dims, using the specified RNG object. Currently, - \"BigRNG\" is the only available Random Number Generator (RNG) for - BigFloats, which may be seeded using srand. - -"), - ("Random Numbers","Base","rand","rand(dims or [dims...]) - Generate a random \"Float64\" array of the size specified by dims. - -"), - -("Random Numbers","Base","rand","rand(BigFloat, dims or [dims...]) - - Generate a random \"BigFloat\" array of the size specified by dims. + Generate a random \"Float64\" array of the size specified by dims "), @@ -4938,14 +4907,6 @@ popdisplay(d::Display) "), -("Random Numbers","Base","randn","randn(BigFloat, dims or [dims...]) - - Generate a normally-distributed random BigFloat with mean 0 and - standard deviation 1. Optionally generate an array of normally- - distributed random BigFloats. - -"), - ("Random Numbers","Base","randn!","randn!(A::Array{Float64, N}) Fill the array A with normally-distributed (mean 0, standard @@ -4953,13 +4914,6 @@ popdisplay(d::Display) "), -("Random Numbers","Base","randn!","randn!(A::Array{BigFloat, N}) - - Fill the array A with normally-distributed (mean 0, standard - deviation 1) random BigFloats. Also see the rand function. - -"), - ("Random Numbers","Base","randsym","randsym(n) Generate a \"nxn\" symmetric array of normally-distributed random diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index f7241ed8afcce..a37b0f1f57d0c 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -3263,27 +3263,19 @@ The `BigFloat` type implements arbitrary-precision floating-point aritmetic usin Random Numbers -------------- -Random number generation in Julia uses the `Mersenne Twister library `_. Julia has a global RNG, which is used by default. Multiple RNGs can be plugged in using the ``AbstractRNG`` object, which can then be used to have multiple streams of random numbers. Currently, only ``MersenneTwister`` is supported. For the generation of BigInts and BigFloats, GMP's own Mersenne Twister implementation is used instead. +Random number generation in Julia uses the `Mersenne Twister library `_. Julia has a global RNG, which is used by default. Multiple RNGs can be plugged in using the ``AbstractRNG`` object, which can then be used to have multiple streams of random numbers. Currently, only ``MersenneTwister`` is supported. .. function:: srand([rng], seed) - Seed the RNG with a ``seed``, which may be an unsigned integer or a vector of unsigned integers. ``seed`` can even be a filename, in which case the seed is read from a file. If the argument ``rng`` is not provided, the default global RNG and the default BigRNG are seeded. + Seed the RNG with a ``seed``, which may be an unsigned integer or a vector of unsigned integers. ``seed`` can even be a filename, in which case the seed is read from a file. If the argument ``rng`` is not provided, the default global RNG is seeded. .. function:: MersenneTwister([seed]) Create a ``MersenneTwister`` RNG object. Different RNG objects can have their own seeds, which may be useful for generating different streams of random numbers. -.. function:: BigRNG([seed]) - - Create a ``BigRNG`` RNG object, used exclusively to generate random BigInts and BigFloats. Different RNG objects can have their own seeds, which may be useful for generating different streams of random numbers. - .. function:: rand() - Generate a ``Float64`` random number uniformly in [0,1). - -.. function:: rand(BigFloat) - - Generate a ``BigFloat`` random number uniformly in [0,1). + Generate a ``Float64`` random number uniformly in [0,1) .. function:: rand!([rng], A) @@ -3293,17 +3285,9 @@ Random number generation in Julia uses the `Mersenne Twister library