Fix Random.nextLong returning value out of range KT-47304
Correctly zero-extend the lower Int part of the Long being produced
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -135,7 +135,7 @@ public abstract class Random {
|
||||
nextInt().toLong() and 0xFFFF_FFFF
|
||||
else -> {
|
||||
val bitCount = fastLog2(nHigh)
|
||||
nextBits(bitCount).toLong().shl(32) + nextInt()
|
||||
nextBits(bitCount).toLong().shl(32) + (nextInt().toLong() and 0xFFFF_FFFF)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user