On Wed, Jun 26, 2019 at 8:48 PM Chou Yan <yan.chou.str...@gmail.com> wrote: > > like this: > r:=rand.New(rand.NewSource(time.Now().Unix())) > for { > r.Intn(96) > } > I know the same seed will generate the same sequence. But I don't know why it > generate mass same number when I use seed of 'time.Now().Unix()', But when I > use seed of 'time.Now().UnixNano()', It will not. > I suspect what this is related to the seqence rand algorithm,But I have no > relevant evidence
This doesn't make sense. Can you reproduce it in the go playground? > > 在 2019年6月27日星期四 UTC+8上午10:32:38,Burak Serdar写道: >> >> On Wed, Jun 26, 2019 at 8:17 PM Chou Yan <yan.ch...@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 golan...@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/99351298-7843-4556-b422-8635eb96c936%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/CAMV2Rqo-twhsXPRdn%3DOV5badmM0h-CZjhXhNnmaQeaXxeKz31g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.