Thread
#stdlib
    Dmitry Kandalov

    Dmitry Kandalov

    3 years ago
    Is there any way to get the seed of
    kotlin.random.Random
    ? I want to use
    Random
    in a test with random seed which I could print in case the test fails.
    orangy

    orangy

    3 years ago
    Get a random value and re-seed with it?
    Dmitry Kandalov

    Dmitry Kandalov

    3 years ago
    Yes, there is an option to use
    Random(seed)
    function. So I guess the answer is “no”.
    marcinmoskala

    marcinmoskala

    3 years ago
    I believe that using MockK you can mock
    Random
    constructor and always set your own seed or store one that was set.https://mockk.io/#constructor-mocks
    Though I believe it would be easier to generate random seed every time, print it and then use it.
    Dmitry Kandalov

    Dmitry Kandalov

    3 years ago
    I ended up doing this
    val random = Random(seed = Random.nextInt().printed("seed="))