I came across something in scala.util.Random
that led me to unnecessary debugging yesterday.
I just needed random Doubles
, and so used scala.util.Random
. For similar seeds (i.e., integers 0 ... N
), I found that the first call to nextDouble()
returned almost identical values; for my purposes of sampling a binned CDF, they were identical.
import scala.util.Random
val seed = 1 to 10
val nums = seed.map(u => new Random(u).nextDouble)
Result:
Vector(0.7308781907032909, 0.7311469360199058, 0.731057369148862, 0.7306094602878371, 0.730519863614471, 0.7307886238322471, 0.7306990420600421, 0.7302511331990172, 0.7301615514268123, 0.7304302967434272)
Is there something I'm not aware of about the scala.util.Random
? Getting almost the same value for different seeds seems very strange to me.
Aucun commentaire:
Enregistrer un commentaire