Search code examples
kotlinkotlin-multiplatform

Source of randomness in kotlin-stdlib-common


In kotlin-stdlib-common is there any source of randomness available out of the box? Whether it's some implementation of standard java.util.Random, kotlin.math.random* or basic current time millis that I can use to create my own random number generator? I can't find any.

If it's not there, how would you get the source of randomness without setting your own platform dependent implementations? This is the only method I need:

expect class Rng {
    fun nextInt(): Int
}

I'm trying to make it platform agnostic.


Solution

  • The answer would be: wait for Kotlin 1.3 to get released where the common library will be enriched with classes and methods that can provide the source for random values.

    https://kotlinlang.org/docs/reference/whatsnew13.html#multiplatform-random