On Wed, Jun 26, 2019 at 8:17 PM Chou Yan <yan.chou.str...@gmail.com> wrote:
>
> I use:
> r:=rand.New(rand.NewSource(time.Now().Unix()))
> r..Intn(96)

How are you generating multiple random numbers? If your loop that
generates these numbers include the r:=rand.New(...), then you're
essentially seeding the random number generator with the same number,
because the program ends before time.Now().Unix() returns a different
value every second.

Move the r:=rand.New(...) outsite the for loop.

> I got:
>
> and val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 39
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> rand val: 82
> ...
> mass common sequential number .
> But if I change that:
> r:=rand.New(rand.NewSource(time.Now().UnixNano()))
> It will not happen.
> Why does this happened? and how do I choose it between time.Now().Unix() or 
> UnixNano()?
>
> --
> 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/ce0671c5-f2df-42d9-a7af-bdef939e6d6d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMV2Rqpq6%2BSAzErGho6o7A-pZ7toYrfZnhYh21A7Y7NV6BEV9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to