solaza
solaza

Reputation: 1291

Difference Java Random and Kotlin Random

What is difference between Java Random and Kotlin Random? Are they using same algorithm?

Upvotes: 2

Views: 629

Answers (2)

Alexey Soshin
Alexey Soshin

Reputation: 17721

Kotlin is intended to run on different platforms, and not only on JVM.

kotlin.random.Random will resolve to different implementations, depending on your platform (JVM/JS/native).

So KotlinJS won't be using the same algorithm as Java does, and for Kotlin on JVM, it also depends to which of the algorithms you're comparing it to.

Upvotes: 2

zsmb13
zsmb13

Reputation: 89608

If you dig down deep enough into the implementation of the kotlin.random.Random type, you'll find that on Java 7 (if you're using the jdk7 artifact), Random.Default will use java.util.Random under the hood (source here), while on Java 8, it will use java.util.concurrent.ThreadLocalRandom (source here).

So the implementation is backed by Java's random facilities in both cases.

Upvotes: 5

Related Questions