On Tue, Mar 14, 2023 at 3:47 PM Kwaku Biney <kwakubi...@gmail.com> wrote:
>
> i was digging in the rand package and came across NewSource(seed) in the 
> randpackage which creates a new source in case you don't want the global 
> source set by the package. It returns a Source interface. For some reason, 
> there's a seed method on the Source as well for which Rand implements, where 
> you pass the seed value. But in the NewSource implementation, there's an 
> rng.Seed() which gets called. Is there a reason why these two seed() calls 
> are necessary and if so, anyone know the difference?
> https://github.com/golang/go/blob/master/src/math/rand/rand.go (edited)

A Source requires a seed to do anything at all, so NewSource takes a
seed value.  It's possible to change an existing Source to start
producing a new sequence of random numbers starting from a new seed,
so Source has a Seed method.  Sure, we could force people to create a
new Source if they want to start a new sequence at a new seed, but
it's easy enough to not require that.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXGJeDhkb_VjC4pkaUo3tU5d2j4QMBJLRx%2B74nn3hBzzQ%40mail.gmail.com.

Reply via email to