diff --git a/base/random/RNGs.jl b/base/random/RNGs.jl index e27a24b42c2d6..84cdf4403f41e 100644 --- a/base/random/RNGs.jl +++ b/base/random/RNGs.jl @@ -313,8 +313,11 @@ rand(r::MersenneTwister, sp::SamplerTrivial{Close1Open2_64}) = #### integers -rand(r::MersenneTwister, T::SamplerUnion(BitInteger)) = mt_pop!(r, T[]) -rand(r::MersenneTwister, ::SamplerType{Bool}) = rand(r, UInt8) % Bool +rand(r::MersenneTwister, T::SamplerUnion(Union{Int64,UInt64,Int128,UInt128})) = + mt_pop!(r, T[]) + +rand(r::MersenneTwister, T::SamplerUnion(Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32})) = + rand(r, UInt52Raw()) % T[] #### arrays of floats diff --git a/test/random.jl b/test/random.jl index 392afc86a662c..ef1ea7d74601d 100644 --- a/test/random.jl +++ b/test/random.jl @@ -278,10 +278,10 @@ let mt = MersenneTwister(0) B = Vector{T}(uninitialized, 31) rand!(mt, A) rand!(mt, B) - @test A[end] == Any[21, 0x4e, -3158, 0x0ded, 2132370312, 0x5e76d222, 1701112237820550475, 0x552ac662d46426bf, - -48946429529471164341432530784191877404, Float16(0.99805), 0.845204f0][i] - @test B[end] == Any[94, 0x14, 22684, 0x0278, -862240437, 0xc425026c, -7329373301769527751, 0x8a40806d8107ce23, - 37650272825719887492093881479739648820, Float16(0.14648), 0.5025569f0][i] + @test A[end] == Any[21, 0x7b, 17385, 0x3086, -1574090021, 0xadcb4460, 6797283068698303107, 0xc8e6453e139271f3, + 69855512850528774484795047199183096941, Float16(0.16895), 0.21086597f0][i] + @test B[end] == Any[49, 0x65, -3725, 0x719d, 814246081, 0xdf61843a, 2120308604158549401, 0xcb28c236e9c0f608, + 61881313582466480231846019869039259750, Float16(0.38672), 0.20027375f0][i] end srand(mt, 0)