christophsturm
12/19/2018, 12:29 PMRandom
instance? or do i have to store the seed and create it from that again?Egor Trutenko
12/19/2018, 12:35 PMRandom
is itself thread-safe, so you can call the same instance from any number of threads;
b) Creating a Random
instance from seed is actually the same as copying an existing instance.Alan Evans
12/19/2018, 12:41 PMchristophsturm
12/19/2018, 12:42 PMAlan Evans
12/19/2018, 12:44 PMAlan Evans
12/19/2018, 12:44 PMfactory { Random(1234) }
Would always inject a random with same seed, 1234
christophsturm
12/19/2018, 12:46 PMAlan Evans
12/19/2018, 12:48 PMAlan Evans
12/19/2018, 12:49 PMAlan Evans
12/19/2018, 12:50 PMRandolfConfig(random = { Random(1234) })
That is, random is of type: () -> Random
i.e. a factory. It creates a new random on demand.
Therefore, no actual Random
instance exists on your config.Alan Evans
12/19/2018, 12:51 PMchristophsturm
12/19/2018, 12:51 PMAlan Evans
12/19/2018, 12:51 PMchristophsturm
12/19/2018, 12:52 PMAlan Evans
12/19/2018, 12:53 PMval oneTimeSeed = Random().next()
RandolfConfig(random = { Random(oneTimeSeed) })
christophsturm
12/19/2018, 12:53 PMAlan Evans
12/19/2018, 12:54 PMchristophsturm
12/19/2018, 12:55 PMAlan Evans
12/19/2018, 1:03 PMSerializable
so if you really wanted to copy it, you can serialize and deserialize.ilya.gorbunov
12/19/2018, 3:07 PMRandom supportsnot yet, if we're talking about Kotlin's RandomSerializable
christophsturm
12/19/2018, 9:48 PM