@@ -7,9 +7,10 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox,
77 big, rationalize, float, trunc, round, floor, ceil, bswap, clamp,
88 div, fld, rem, mod, mod1, fld1, min, max, minmax,
99 signed, unsigned, copysign, flipsign, signbit,
10- rand, length
10+ length
1111
1212import Statistics # for _mean_promote
13+ import Random: Random, AbstractRNG, SamplerType, rand!
1314
1415using Base. Checked: checked_add, checked_sub, checked_div
1516
@@ -315,7 +316,7 @@ const UF = (N0f8, N6f10, N4f12, N2f14, N0f16)
315316promote_rule (:: Type{X} , :: Type{Tf} ) where {X <: FixedPoint , Tf <: AbstractFloat } =
316317 promote_type (floattype (X), Tf)
317318
318- # Note that `Tr` does not always have enough domains.
319+ # Note that `Tr` does not always have enough domains.
319320promote_rule (:: Type{X} , :: Type{Tr} ) where {X <: FixedPoint , Tr <: Rational } = Tr
320321
321322promote_rule (:: Type{X} , :: Type{Ti} ) where {X <: FixedPoint , Ti <: Integer } = floattype (X)
@@ -382,8 +383,15 @@ scaledual(::Type{Tdual}, x::AbstractArray{T}) where {Tdual, T <: FixedPoint} =
382383 throw (ArgumentError (String (take! (io))))
383384end
384385
385- rand (:: Type{T} ) where {T <: FixedPoint } = reinterpret (T, rand (rawtype (T)))
386- rand (:: Type{T} , sz:: Dims ) where {T <: FixedPoint } = reinterpret (T, rand (rawtype (T), sz))
386+ function Random. rand (r:: AbstractRNG , :: SamplerType{X} ) where X <: FixedPoint
387+ X (rand (r, rawtype (X)), 0 )
388+ end
389+
390+ function rand! (r:: AbstractRNG , A:: Array{X} , :: SamplerType{X} ) where {T, X <: FixedPoint{T} }
391+ At = unsafe_wrap (Array, reinterpret (Ptr{T}, pointer (A)), size (A))
392+ Random. rand! (r, At, SamplerType {T} ())
393+ A
394+ end
387395
388396if VERSION >= v " 1.1" # work around https://github.com/JuliaLang/julia/issues/34121
389397 include (" precompile.jl" )
0 commit comments