thx. you are right. I make a mistake. I negleck that my func will be called 
by mass goroutine, it will get the same seed and the same sequence

在 2019年6月27日星期四 UTC+8上午11:07:28,Kurtis Rader写道:
>
> Works for me: https://play.golang.org/p/zD5F7gp41re
>
> Like Burak I suspect you are initializing the RNG in a tight loop. Since 
> `time.Now().Unix()` has a resolution of one second you end up generating 
> the same initial value every time through the loop until the current time 
> advances to the next second.
>
> On Wed, Jun 26, 2019 at 7:48 PM Chou Yan <yan.ch...@gmail.com 
> <javascript:>> 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
>>
>> 在 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 golan...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/99351298-7843-4556-b422-8635eb96c936%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/99351298-7843-4556-b422-8635eb96c936%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> 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/1e5a8486-ef43-4258-8ffc-d21dc542638f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to