go - Save random state in golang -


is there way save random state in golang math/rand package?

i serialize , store later use, random state interface , concrete struct underneath interface unexported (so json.marshall apparently cannot used).

as alternative saving rand.source object, thought saving underlying int64 seed value. can set rand.seed, don't see way obtain seed value can retained later use.

you can make own random number source can marshalled.

one way copy code http://golang.org/src/math/rand/rng.go , adapt adding code can marshal state in whatever way want. that'll give own rand.source can use in rand.new(myrandsource) generate random numbers.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -