Provide common Random API
#KT-17261
This commit is contained in:
@@ -18,9 +18,13 @@
|
||||
package kotlin.internal.jdk7
|
||||
|
||||
import kotlin.internal.PlatformImplementations
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.jdk7.PlatformThreadLocalRandom
|
||||
|
||||
internal open class JDK7PlatformImplementations : PlatformImplementations() {
|
||||
|
||||
override fun addSuppressed(cause: Throwable, exception: Throwable) = cause.addSuppressed(exception)
|
||||
|
||||
override fun defaultPlatformRandom(): Random = PlatformThreadLocalRandom()
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.random.jdk7
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "CANNOT_OVERRIDE_INVISIBLE_MEMBER")
|
||||
internal class PlatformThreadLocalRandom : kotlin.random.AbstractPlatformRandom() {
|
||||
override val impl: ThreadLocalRandom get() = ThreadLocalRandom.current()
|
||||
|
||||
override fun nextLong(bound: Long): Long = impl.nextLong(bound)
|
||||
override fun nextLong(origin: Long, bound: Long): Long = impl.nextLong(origin, bound)
|
||||
override fun nextInt(bound: Int): Int = impl.nextInt(bound)
|
||||
override fun nextInt(origin: Int, bound: Int): Int = impl.nextInt(origin, bound)
|
||||
}
|
||||
Reference in New Issue
Block a user