Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 1a8885b

Browse files
committed
Revert "Merge branch 'bigrng' of github.com:andrioni/julia into andrioni-bigrng"
This reverts commit 4cc21ca, reversing changes made to 4f9a2a9.
1 parent ef3bece commit 1a8885b

File tree

7 files changed

+11
-232
lines changed

7 files changed

+11
-232
lines changed

base/exports.jl

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export
2222
Bidiagonal,
2323
BigFloat,
2424
BigInt,
25-
BigRNG,
2625
BitArray,
2726
BitMatrix,
2827
BitVector,

base/gmp.jl

+2-85
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module GMP
22

3-
export BigInt, BigRNG
3+
export BigInt
44

55
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($),
66
binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod,
77
ndigits, promote_rule, rem, show, isqrt, string, isprime, powermod,
88
widemul, sum, trailing_zeros, trailing_ones, count_ones, base, parseint,
99
serialize, deserialize, bin, oct, dec, hex, isequal, invmod,
10-
prevpow2, nextpow2, ndigits0z, rand, rand!, srand
10+
prevpow2, nextpow2, ndigits0z
1111

1212
type BigInt <: Integer
1313
alloc::Cint
@@ -419,87 +419,4 @@ widemul{T<:Integer}(x::T, y::T) = BigInt(x)*BigInt(y)
419419
prevpow2(x::BigInt) = x < 0 ? -prevpow2(-x) : (x <= 2 ? x : one(BigInt) << (ndigits(x, 2)-1))
420420
nextpow2(x::BigInt) = x < 0 ? -nextpow2(-x) : (x <= 2 ? x : one(BigInt) << ndigits(x-1, 2))
421421

422-
# Random number generation
423-
type BigRNG <: AbstractRNG
424-
seed_alloc::Cint
425-
seed_size::Cint
426-
seed_d::Ptr{Void}
427-
alg::Cint
428-
alg_data::Ptr{Void}
429-
430-
function BigRNG()
431-
randstate = new(zero(Cint), zero(Cint), C_NULL, zero(Cint), C_NULL)
432-
# The default algorithm in GMP is currently MersenneTwister
433-
ccall((:__gmp_randinit_default, :libgmp), Void, (Ptr{BigRNG},),
434-
&randstate)
435-
finalizer(randstate, BigRNG_clear)
436-
randstate
437-
end
438-
end
439-
440-
# Initialize with seed
441-
function BigRNG(seed::Uint64)
442-
randstate = BigRNG()
443-
ccall((:__gmp_randseed_ui, :libgmp), Void, (Ptr{BigRNG}, Culong),
444-
&randstate, seed)
445-
randstate
446-
end
447-
function BigRNG(seed::BigInt)
448-
randstate = BigRNG()
449-
ccall((:__gmp_randseed, :libgmp), Void, (Ptr{BigRNG}, Ptr{BigInt}),
450-
&randstate, &seed)
451-
randstate
452-
end
453-
454-
function BigRNG_clear(x::BigRNG)
455-
ccall((:__gmp_randclear, :libgmp), Void, (Ptr{BigRNG},), &x)
456-
end
457-
458-
function rand(::Type{BigInt}, randstate::BigRNG, n::Integer)
459-
m = convert(BigInt, n)
460-
randu(randstate, m)
461-
end
462-
463-
function rand(r::Range1{BigInt})
464-
ulen = convert(BigInt, length(r))
465-
convert(BigInt, first(r) + randu(ulen))
466-
end
467-
468-
function rand!(r::Range1{BigInt}, A::Array{BigInt})
469-
for i = 1:length(A)
470-
A[i] = rand(r)
471-
end
472-
A
473-
end
474-
475-
rand(r::Range1{BigInt}, dims::Dims) = rand!(r, Array(BigInt, dims))
476-
rand(r::Range1{BigInt}, dims::Int...) = rand!(r, Array(BigInt, dims...))
477-
478-
function randu(randstate::BigRNG, k::BigInt)
479-
z = BigInt()
480-
ccall((:__gmpz_urandomm, :libgmp), Void,
481-
(Ptr{BigInt}, Ptr{BigRNG}, Ptr{BigInt}), &z, &randstate, &k)
482-
z
483-
end
484-
randu(k::BigInt) = randu(Base.Random.DEFAULT_BIGRNG, k)
485-
486-
srand(r::BigRNG, seed) = srand(r, convert(BigInt, seed))
487-
function srand(randstate::BigRNG, seed::Vector{Uint32})
488-
s = big(0)
489-
for i in seed
490-
s = s << 32 + i
491-
end
492-
srand(randstate, s)
493-
end
494-
function srand(randstate::BigRNG, seed::Uint64)
495-
ccall((:__gmp_randseed_ui, :libgmp), Void, (Ptr{BigRNG}, Culong),
496-
&randstate, seed)
497-
return
498-
end
499-
function srand(randstate::BigRNG, seed::BigInt)
500-
ccall((:__gmp_randseed, :libgmp), Void, (Ptr{BigRNG}, Ptr{BigInt}),
501-
&randstate, &seed)
502-
return
503-
end
504-
505422
end # module

base/mpfr.jl

+1-39
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import
1717
itrunc, eps, signbit, sin, cos, tan, sec, csc, cot, acos, asin, atan,
1818
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2,
1919
serialize, deserialize, inf, nan, hash, cbrt, typemax, typemin,
20-
realmin, realmax, get_rounding, set_rounding,
21-
rand, rand!, randn, randn!
20+
realmin, realmax, get_rounding, set_rounding
2221

2322
import Base.Math.lgamma_r
2423

@@ -733,41 +732,4 @@ function hash(x::BigFloat)
733732
h
734733
end
735734

736-
# RNG-related functions
737-
function rand(::Type{BigFloat}, randstate::BigRNG)
738-
z = BigFloat()
739-
ccall((:mpfr_urandom,:libmpfr), Int32,
740-
(Ptr{BigFloat}, Ptr{BigRNG}, Int32),
741-
&z, &randstate, ROUNDING_MODE[end])
742-
z
743-
end
744-
rand(::Type{BigFloat}) = rand(BigFloat, Base.Random.DEFAULT_BIGRNG)
745-
746-
function rand!(r::BigRNG, A::Array{BigFloat})
747-
for i = 1:length(A)
748-
A[i] = rand(BigFloat, r)
749-
end
750-
A
751-
end
752-
rand!(A::Array{BigFloat}) = rand!(Base.Random.DEFAULT_BIGRNG, A)
753-
754-
function randn(::Type{BigFloat}, randstate::BigRNG)
755-
z = BigFloat()
756-
ccall((:mpfr_grandom,:libmpfr), Int32,
757-
(Ptr{BigFloat}, Ptr{BigFloat}, Ptr{BigRNG}, Int32),
758-
&z, C_NULL, &randstate, ROUNDING_MODE[end])
759-
z
760-
end
761-
randn(::Type{BigFloat}) = randn(BigFloat, Base.Random.DEFAULT_BIGRNG)
762-
randn(::Type{BigFloat}, dims::Dims) = randn!(Array(BigFloat, dims))
763-
randn(::Type{BigFloat}, dims::Int...) = randn!(Array(BigFloat, dims...))
764-
765-
function randn!(r::BigRNG, A::Array{BigFloat})
766-
for i = 1:length(A)
767-
A[i] = randn(BigFloat, r)
768-
end
769-
A
770-
end
771-
randn!(A::Array{BigFloat}) = randn!(Base.Random.DEFAULT_BIGRNG, A)
772-
773735
end #module

base/random.jl

+1-8
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ function librandom_init()
5454
seed = reinterpret(Uint64, time())
5555
seed = bitmix(seed, uint64(getpid()))
5656
try
57-
@linux_only seed = bitmix(seed, parseint(Uint64, readall(`ifconfig` |> `sha1sum`)[1:40], 16))
58-
@osx_only seed = bitmix(seed, parseint(Uint64, readall(`ifconfig` |> `shasum`)[1:40], 16))
57+
seed = bitmix(seed, parseint(Uint64, readall(`ifconfig` |> `sha1sum`)[1:40], 16))
5958
catch
6059
# ignore
6160
end
@@ -76,12 +75,6 @@ end
7675
function srand(seed::Vector{Uint32})
7776
global RANDOM_SEED = seed
7877
dsfmt_gv_init_by_array(seed)
79-
s = big(0)
80-
for i in Base.Random.RANDOM_SEED
81-
s = s << 32 + i
82-
end
83-
global DEFAULT_BIGRNG = BigRNG(s)
84-
return
8578
end
8679
srand(n::Integer) = srand(make_seed(n))
8780

doc/helpdb.jl

+3-49
Original file line numberDiff line numberDiff line change
@@ -4830,8 +4830,7 @@ popdisplay(d::Display)
48304830
Seed the RNG with a \"seed\", which may be an unsigned integer or a
48314831
vector of unsigned integers. \"seed\" can even be a filename, in
48324832
which case the seed is read from a file. If the argument \"rng\" is
4833-
not provided, the default global RNG and the default BigRNG are
4834-
seeded.
4833+
not provided, the default global RNG is seeded.
48354834
48364835
"),
48374836

@@ -4843,24 +4842,9 @@ popdisplay(d::Display)
48434842
48444843
"),
48454844

4846-
("Random Numbers","Base","BigRNG","BigRNG([seed])
4847-
4848-
Create a \"BigRNG\" RNG object, used exclusively to generate random
4849-
BigInts and BigFloats. Different RNG objects can have their own
4850-
seeds, which may be useful for generating different streams of
4851-
random numbers.
4852-
4853-
"),
4854-
48554845
("Random Numbers","Base","rand","rand()
48564846
4857-
Generate a \"Float64\" random number uniformly in [0,1).
4858-
4859-
"),
4860-
4861-
("Random Numbers","Base","rand","rand(BigFloat)
4862-
4863-
Generate a \"BigFloat\" random number uniformly in [0,1).
4847+
Generate a \"Float64\" random number uniformly in [0,1)
48644848
48654849
"),
48664850

@@ -4880,24 +4864,9 @@ popdisplay(d::Display)
48804864
48814865
"),
48824866

4883-
("Random Numbers","Base","rand","rand(BigFloat, rng::AbstractRNG[, dims...])
4884-
4885-
Generate a random \"BigFloat\" number or array of the size
4886-
specified by dims, using the specified RNG object. Currently,
4887-
\"BigRNG\" is the only available Random Number Generator (RNG) for
4888-
BigFloats, which may be seeded using srand.
4889-
4890-
"),
4891-
48924867
("Random Numbers","Base","rand","rand(dims or [dims...])
48934868
4894-
Generate a random \"Float64\" array of the size specified by dims.
4895-
4896-
"),
4897-
4898-
("Random Numbers","Base","rand","rand(BigFloat, dims or [dims...])
4899-
4900-
Generate a random \"BigFloat\" array of the size specified by dims.
4869+
Generate a random \"Float64\" array of the size specified by dims
49014870
49024871
"),
49034872

@@ -4938,28 +4907,13 @@ popdisplay(d::Display)
49384907
49394908
"),
49404909

4941-
("Random Numbers","Base","randn","randn(BigFloat, dims or [dims...])
4942-
4943-
Generate a normally-distributed random BigFloat with mean 0 and
4944-
standard deviation 1. Optionally generate an array of normally-
4945-
distributed random BigFloats.
4946-
4947-
"),
4948-
49494910
("Random Numbers","Base","randn!","randn!(A::Array{Float64, N})
49504911
49514912
Fill the array A with normally-distributed (mean 0, standard
49524913
deviation 1) random numbers. Also see the rand function.
49534914
49544915
"),
49554916

4956-
("Random Numbers","Base","randn!","randn!(A::Array{BigFloat, N})
4957-
4958-
Fill the array A with normally-distributed (mean 0, standard
4959-
deviation 1) random BigFloats. Also see the rand function.
4960-
4961-
"),
4962-
49634917
("Random Numbers","Base","randsym","randsym(n)
49644918
49654919
Generate a \"nxn\" symmetric array of normally-distributed random

doc/stdlib/base.rst

+4-28
Original file line numberDiff line numberDiff line change
@@ -3263,27 +3263,19 @@ The `BigFloat` type implements arbitrary-precision floating-point aritmetic usin
32633263
Random Numbers
32643264
--------------
32653265

3266-
Random number generation in Julia uses the `Mersenne Twister library <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT>`_. 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.
3266+
Random number generation in Julia uses the `Mersenne Twister library <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT>`_. 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.
32673267

32683268
.. function:: srand([rng], seed)
32693269

3270-
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.
3270+
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.
32713271

32723272
.. function:: MersenneTwister([seed])
32733273

32743274
Create a ``MersenneTwister`` RNG object. Different RNG objects can have their own seeds, which may be useful for generating different streams of random numbers.
32753275

3276-
.. function:: BigRNG([seed])
3277-
3278-
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.
3279-
32803276
.. function:: rand()
32813277

3282-
Generate a ``Float64`` random number uniformly in [0,1).
3283-
3284-
.. function:: rand(BigFloat)
3285-
3286-
Generate a ``BigFloat`` random number uniformly in [0,1).
3278+
Generate a ``Float64`` random number uniformly in [0,1)
32873279

32883280
.. function:: rand!([rng], A)
32893281

@@ -3293,17 +3285,9 @@ Random number generation in Julia uses the `Mersenne Twister library <http://www
32933285

32943286
Generate a random ``Float64`` number or array of the size specified by dims, using the specified RNG object. Currently, ``MersenneTwister`` is the only available Random Number Generator (RNG), which may be seeded using srand.
32953287

3296-
.. function:: rand(BigFloat, rng::AbstractRNG, [dims...])
3297-
3298-
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.
3299-
33003288
.. function:: rand(dims or [dims...])
33013289

3302-
Generate a random ``Float64`` array of the size specified by dims.
3303-
3304-
.. function:: rand(BigFloat, dims or [dims...])
3305-
3306-
Generate a random ``BigFloat`` array of the size specified by dims.
3290+
Generate a random ``Float64`` array of the size specified by dims
33073291

33083292
.. function:: rand(Int32|Uint32|Int64|Uint64|Int128|Uint128, [dims...])
33093293

@@ -3325,18 +3309,10 @@ Random number generation in Julia uses the `Mersenne Twister library <http://www
33253309

33263310
Generate a normally-distributed random number with mean 0 and standard deviation 1. Optionally generate an array of normally-distributed random numbers.
33273311

3328-
.. function:: randn(BigFloat, dims or [dims...])
3329-
3330-
Generate a normally-distributed random BigFloat with mean 0 and standard deviation 1. Optionally generate an array of normally-distributed random BigFloats.
3331-
33323312
.. function:: randn!(A::Array{Float64,N})
33333313

33343314
Fill the array A with normally-distributed (mean 0, standard deviation 1) random numbers. Also see the rand function.
33353315

3336-
.. function:: randn!(A::Array{BigFloat,N})
3337-
3338-
Fill the array A with normally-distributed (mean 0, standard deviation 1) random BigFloats. Also see the rand function.
3339-
33403316
.. function:: randsym(n)
33413317

33423318
Generate a ``nxn`` symmetric array of normally-distributed random numbers with mean 0 and standard deviation 1.

test/random.jl

-22
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,3 @@ if sizeof(Int32) < sizeof(Int)
2222
@test typeof(r) == Int32
2323
@test -1 <= r <= typemax(Int32)
2424
end
25-
26-
range = big(typemax(Int128)):(big(typemax(Int128)) + 10000)
27-
@test rand(range) != rand(range)
28-
@test big(typemax(Int128)) <= rand(range) <= big(typemax(Int128)) + 10000
29-
r = rand(range, 1, 2)
30-
@test size(r) == (1, 2)
31-
@test typeof(r) == Matrix{BigInt}
32-
33-
srand(0)
34-
r = rand(range)
35-
f = rand(BigFloat)
36-
srand(0)
37-
@test rand(range) == r
38-
@test rand(BigFloat) == f
39-
40-
@test rand(BigFloat) != rand(BigFloat)
41-
@test 0.0 <= rand(BigFloat) < 1.0
42-
@test typeof(rand(BigFloat)) == BigFloat
43-
44-
r = rand(BigFloat, 1, 3)
45-
@test size(r) == (1, 3)
46-
@test typeof(r) == Matrix{BigFloat}

0 commit comments

Comments
 (0)