On Wed, Jun 26, 2019 at 8:30 PM Chou Yan <yan.chou.str...@gmail.com> wrote:

> // NewRandW creates a new RandW with a random object.
> func NewRandW() *RandW {
> return &RandW{r: rand.New(rand.NewSource(time.Now().Unix()))}
> }
>

That is broken even if you use `UnixNano()`. Repeat after me: In general
you should never initialize a RNG more than once. I say "in general"
because there are use cases where reproducible results require doing so.
But those use cases do not seem to be applicable to your situation. Without
knowing more about why you are creating multiple RNGs the general advice is
create a single RNG and use it every place you need a random number. You
should probably be using `rand.Seed()` and `rand.Source()` rather than
`rand.NewSource()` given your fundamental misunderstanding about how RNGs
work.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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/CABx2%3DD9J%2BvKtapgYvkRx%3DviPez%2BLG40JjPzXEdgJQAwcLaxMrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to