Skip to content

Commit 88f0707

Browse files
Merge pull request #110 from roosephu/master
Use rng
2 parents 83c696b + aa57339 commit 88f0707

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/extras/random.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ function rand(rng::AbstractRNG, ::Random.SamplerTrivial{Random.CloseOpen01{Doubl
99
frlo, xplo = frexp(lo)
1010
xplo = Base.exponent(hi) - min(1, fld(xplo,4)) - abs(Base.exponent(eps(hi)))
1111
lo = ldexp(frlo, xplo)
12-
lo = rand(Bool) ? lo : -lo
12+
lo = rand(rng, Bool) ? lo : -lo
1313

1414
DoubleFloat(hi, lo)
1515
end
1616

1717
function rand(rng::AbstractRNG, ::Random.SamplerTrivial{Random.CloseOpen01{Complex{DoubleFloat{T}}}}) where {T<:IEEEFloat}
18-
re = rand(DoubleFloat{T})
19-
im = rand(DoubleFloat{T})
18+
re = rand(rng, DoubleFloat{T})
19+
im = rand(rng, DoubleFloat{T})
2020
return Complex{DoubleFloat{T}}(re, im)
2121
end
2222

@@ -28,7 +28,7 @@ end
2828

2929
function randpm(rng::MersenneTwister, ::Type{DoubleFloat{T}}) where {T<:IEEEFloat}
3030
r = rand(rng, DoubleFloat{T})
31-
r = rand(Bool) ? r : -r
31+
r = rand(rng, Bool) ? r : -r
3232
return r
3333
end
3434

@@ -81,18 +81,18 @@ end
8181
# normal variates
8282

8383
function randn(rng::AbstractRNG, ::Type{DoubleFloat{T}}) where {T<:IEEEFloat}
84-
urand1, urand2 = rand(DoubleFloat{T}, 2)
84+
urand1, urand2 = rand(rng, DoubleFloat{T}, 2)
8585
urand1 = urand1 + urand1 - 1
8686
urand2 = urand2 + urand2 - 1
8787
s = urand1*urand1 + urand2*urand2
88-
88+
8989
while s >= 1 || s === 0
90-
urand1, urand2 = rand(DoubleFloat{T}, 2)
90+
urand1, urand2 = rand(rng, DoubleFloat{T}, 2)
9191
urand1 = urand1 + urand1 - 1
9292
urand2 = urand2 + urand2 - 1
9393
s = urand1*urand1 + urand2*urand2
9494
end
95-
95+
9696
s = sqrt( -log(s) / s )
9797
return (urand1 + urand2) * s
9898
end

0 commit comments

Comments
 (0)