https://kotlinlang.org logo
#stdlib
Title
# stdlib
d

Dmitry Kandalov

01/04/2019, 5:46 PM
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.
o

orangy

01/04/2019, 6:03 PM
Get a random value and re-seed with it?
d

Dmitry Kandalov

01/04/2019, 6:40 PM
Yes, there is an option to use
Random(seed)
function. So I guess the answer is “no”.
m

marcinmoskala

01/07/2019, 2:00 PM
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
😱 1
😅 1
Though I believe it would be easier to generate random seed every time, print it and then use it.
d

Dmitry Kandalov

01/07/2019, 11:54 PM
I ended up doing this
val random = Random(seed = Random.nextInt().printed("seed="))
👍 1
119 Views