scalanlp / breeze

Breeze is/was a numerical processing library for Scala.
https://www.scalanlp.org
Apache License 2.0
3.45k stars 693 forks source link

ThreadLocalRandomGenerator not serializable #806

Closed rpiotrow closed 3 years ago

rpiotrow commented 3 years ago

Below code:

val generator = new ThreadLocalRandomGenerator(new MersenneTwister())
val outputStream = new ByteArrayOutputStream(512)
val out = new ObjectOutputStream(outputStream)
try {
  out.writeObject(generator)
  outputStream.toByteArray
} catch {
  case ex: IOException => throw new SerializationException(ex)
} finally {
  if (out != null) out.close()
}

throws exception:

java.io.NotSerializableException: breeze.stats.distributions.ThreadLocalRandomGenerator$$anon$1

ThreadLocalRandomGenerator has value that is not serializabled (ThreadLocal)