Skip to content

Commit dd13878

Browse files
fix typo in Float32 random number generation (#57338)
introduced in #56144 --------- Co-authored-by: Mosè Giordano <[email protected]>
1 parent 8c62f42 commit dd13878

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

stdlib/Random/src/XoshiroSimd.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ simdThreshold(::Type{Bool}) = 640
4646
ui = (x>>>32) % UInt32
4747
li = x % UInt32
4848
u = _uint2float(ui, Float32)
49-
l = _uint2float(ui, Float32)
49+
l = _uint2float(li, Float32)
5050
(UInt64(reinterpret(UInt32, u)) << 32) | UInt64(reinterpret(UInt32, l))
5151
end
5252
@inline function _bits2float(x::UInt64, ::Type{Float16})

stdlib/Random/test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,16 @@ end
12501250
@test length(xs) == 3
12511251
end
12521252

1253+
@testset "Float32 RNG typo" begin
1254+
for T in (Float16, Float32, Float64)
1255+
# Make sure generated numbers are sufficiently diverse
1256+
# for both SIMD and non-SIMD RNG code paths for all types.
1257+
@test length(unique!(rand(T, 7))) > 3
1258+
@test length(unique!(rand(T, 14))) > 10
1259+
@test length(unique!(rand(T, 34))) > 20
1260+
end
1261+
end
1262+
12531263
@testset "Docstrings" begin
12541264
@test isempty(Docs.undocumented_names(Random))
12551265
end

0 commit comments

Comments
 (0)