Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread peterGo
Ryan,

It's not weird.

https://play.golang.org  -> About

In the playground the time begins at 2009-11-10 23:00:00 UTC (determining 
the significance of this date is an exercise for the reader). This makes it 
easier to cache programs by giving them deterministic output.

Peter

On Monday, May 8, 2017 at 1:00:00 PM UTC-4, Ryan C. Decker wrote:
>
> See here: https://play.golang.org/p/EjdQRUnwQF
>
> The weird thing is that time.Now().UnixNano() doesn't appear to ever 
> change in the playground...
>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread Decker, Ryan C.
See here: https://play.golang.org/p/EjdQRUnwQF

The weird thing is that time.Now().UnixNano() doesn't appear to ever change
in the playground...

On Mon, May 8, 2017 at 10:21 AM, Decker, Ryan C.  wrote:

> I usually follow the example and go with time.Now().UnixNano() which you
> can see here:
>
>
> On Mon, May 8, 2017 at 10:07 AM, messju mohr 
> wrote:
>
>> Hi,
>>
>> in xrand() you are initialising r with the same constant seed for
>> every call, so you always get the same pseudo random number.
>>
>> See: 
>>
>> cheers
>> messju
>>
>>
>> On Mon, May 08, 2017 at 03:26:08AM -0700, sivarajshabin...@gmail.com
>> wrote:
>> >Hi All,
>> >
>> >Firstly, sorry for the title that sounds like a click bait. I am not
>> >understanding what exactly is wrong with this program
>> >[1]https://play.golang.org/p/Tl0wpaCqK7
>> >
>> >package main
>> >
>> >import  (
>> >"fmt"
>> >"math/rand"
>> >"runtime"
>> >)
>> >
>> >func xrand()  int  {
>> >r := rand.New(rand.NewSource(99))
>> >return r.Int()
>> >}
>> >
>> >func main()  {
>> >fmt.Printf("Version %s\n", runtime.Version())
>> >fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n", xrand(),
>> xrand(),
>> >xrand())
>> >
>> >r1 := rand.New(rand.NewSource(99))
>> >fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n", r1.Int(),
>> >r1.Int(), r1.Int())
>> >}
>> >Output
>> >
>> >  Version go1.8
>> >  looks buggy 1: 1108929909, 2: 1108929909, 3: 1108929909
>> >  Looks find  1: 1108929909, 2: 1298032409, 3: 913431059
>> >
>> >When I generate a random number with "math/rand", like the example
>> given
>> >in documentation [2]https://play.golang.org/p/O2k_za0AW7 except
>> that I
>> >return the randomly generated integer from a function, But the
>> function
>> >keeps returning the same value any number of time I call it. On the
>> >contrary running the same code from the main generates random values,
>> >there isn't a reason to doubt rand package. However in the second
>> print
>> >statement where random numbers are properly generated the first value
>> >always is the same value returned by xrand(), here there is
>> something to
>> >doubt rand package.
>> >
>> >What am I missing here?  Could it be a bug?
>> >
>> >Thanks in advance.
>> >
>> >Cheers
>> >Shabinesh
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Ryan C. Decker '08
> Sr. Network & Systems Engineer
> Siena College ITS
> 515 Loudon Road
> Loudonville, NY 12211
> rdec...@siena.edu
>
> CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is for the
> sole use of the intended recipient(s) and may contain confidential and
> privileged information. Any unauthorized review, use, disclosure, or
> distribution is prohibited. If you received this e-mail and are not the
> intended recipient, please inform the sender by e-mail reply and destroy
> all copies of the original message.
>



-- 
Ryan C. Decker '08
Sr. Network & Systems Engineer
Siena College ITS
515 Loudon Road
Loudonville, NY 12211
rdec...@siena.edu

CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is for the
sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure, or
distribution is prohibited. If you received this e-mail and are not the
intended recipient, please inform the sender by e-mail reply and destroy
all copies of the original message.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread Decker, Ryan C.
I usually follow the example and go with time.Now().UnixNano() which you
can see here:


On Mon, May 8, 2017 at 10:07 AM, messju mohr 
wrote:

> Hi,
>
> in xrand() you are initialising r with the same constant seed for
> every call, so you always get the same pseudo random number.
>
> See: 
>
> cheers
> messju
>
>
> On Mon, May 08, 2017 at 03:26:08AM -0700, sivarajshabin...@gmail.com
> wrote:
> >Hi All,
> >
> >Firstly, sorry for the title that sounds like a click bait. I am not
> >understanding what exactly is wrong with this program
> >[1]https://play.golang.org/p/Tl0wpaCqK7
> >
> >package main
> >
> >import  (
> >"fmt"
> >"math/rand"
> >"runtime"
> >)
> >
> >func xrand()  int  {
> >r := rand.New(rand.NewSource(99))
> >return r.Int()
> >}
> >
> >func main()  {
> >fmt.Printf("Version %s\n", runtime.Version())
> >fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n", xrand(),
> xrand(),
> >xrand())
> >
> >r1 := rand.New(rand.NewSource(99))
> >fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n", r1.Int(),
> >r1.Int(), r1.Int())
> >}
> >Output
> >
> >  Version go1.8
> >  looks buggy 1: 1108929909, 2: 1108929909, 3: 1108929909
> >  Looks find  1: 1108929909, 2: 1298032409, 3: 913431059
> >
> >When I generate a random number with "math/rand", like the example
> given
> >in documentation [2]https://play.golang.org/p/O2k_za0AW7 except that
> I
> >return the randomly generated integer from a function, But the
> function
> >keeps returning the same value any number of time I call it. On the
> >contrary running the same code from the main generates random values,
> >there isn't a reason to doubt rand package. However in the second
> print
> >statement where random numbers are properly generated the first value
> >always is the same value returned by xrand(), here there is something
> to
> >doubt rand package.
> >
> >What am I missing here?  Could it be a bug?
> >
> >Thanks in advance.
> >
> >Cheers
> >Shabinesh
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Ryan C. Decker '08
Sr. Network & Systems Engineer
Siena College ITS
515 Loudon Road
Loudonville, NY 12211
rdec...@siena.edu

CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is for the
sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure, or
distribution is prohibited. If you received this e-mail and are not the
intended recipient, please inform the sender by e-mail reply and destroy
all copies of the original message.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread shabinesh sivaraj
Thank you all for replying. I get it now.

On 8 May 2017 8:20 pm, "messju mohr"  wrote:

>
> It's not strange, it's intended behaviour of the playground. See the
> "about" page of the playground:
> "[...] In the playground the time begins at 2009-11-10 23:00:00 UTC
> (determining the significance of this date is an exercise for the reader).
> This makes it easier to cache programs by giving them deterministic output.
> [...]"
>
>
> On Mon, May 08, 2017 at 10:22:14AM -0400, Decker, Ryan C. wrote:
> >See here: [1]https://play.golang.org/p/EjdQRUnwQF
> >The weird thing is that time.Now().UnixNano() doesn't appear to ever
> >change in the playground...
> >On Mon, May 8, 2017 at 10:21 AM, Decker, Ryan C. <[2]
> rdec...@siena.edu>
> >wrote:
> >
> >  I usually follow the example and go with time.Now().UnixNano()
> which you
> >  can see here:
> >  On Mon, May 8, 2017 at 10:07 AM, messju mohr
> >  <[3]mes...@lammfellpuschen.de> wrote:
> >
> >Hi,
> >
> >in xrand() you are initialising r with the same constant seed for
> >every call, so you always get the same pseudo random number.
> >
> >See: <[4]https://play.golang.org/p/XwNmYv5nzJ>
> >
> >cheers
> >messju
> >
> >On Mon, May 08, 2017 at 03:26:08AM -0700,
> >[5]sivarajshabin...@gmail.com wrote:
> >>Hi All,
> >>
> >>Firstly, sorry for the title that sounds like a click bait. I
> >am not
> >>understanding what exactly is wrong with this program
> >>[1][6]https://play.golang.org/p/Tl0wpaCqK7
> >>
> >>package main
> >>
> >>import  (
> >>"fmt"
> >>"math/rand"
> >>"runtime"
> >>)
> >>
> >>func xrand()  int  {
> >>r := rand.New(rand.NewSource(99))
> >>return r.Int()
> >>}
> >>
> >>func main()  {
> >>fmt.Printf("Version %s\n", runtime.Version())
> >>fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n",
> >xrand(), xrand(),
> >>xrand())
> >>
> >>r1 := rand.New(rand.NewSource(99))
> >>fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n",
> >r1.Int(),
> >>r1.Int(), r1.Int())
> >>}
> >>Output
> >>
> >>  Version go1.8
> >>  looks buggy 1: 1108929909, 2: 1108929909, 3: 1108929909
> >>  Looks find  1: 1108929909, 2: 1298032409, 3: 913431059
> >>
> >>When I generate a random number with "math/rand", like the
> >example given
> >>in documentation [2][7]https://play.golang.org/p/O2k_za0AW7
> >except that I
> >>return the randomly generated integer from a function, But
> the
> >function
> >>keeps returning the same value any number of time I call it.
> On
> >the
> >>contrary running the same code from the main generates random
> >values,
> >>there isn't a reason to doubt rand package. However in the
> >second print
> >>statement where random numbers are properly generated the
> first
> >value
> >>always is the same value returned by xrand(), here there is
> >something to
> >>doubt rand package.
> >>
> >>What am I missing here?  Could it be a bug?
> >>
> >>Thanks in advance.
> >>
> >>Cheers
> >>Shabinesh
> >--
> >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 [8]golang-nuts+unsubscr...@googlegroups.com.
> >For more options, visit [9]https://groups.google.com/d/optout.
> >
> >  --
> >  Ryan C. Decker '08
> >  Sr. Network & Systems Engineer
> >  Siena College ITS
> >  515 Loudon Road
> >  Loudonville, NY 12211
> >  [10]rdec...@siena.edu
> >  CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is
> for
> >  the sole use of the intended recipient(s) and may contain
> confidential
> >  and privileged information. Any unauthorized review, use,
> disclosure, or
> >  distribution is prohibited. If you received this e-mail and are not
> the
> >  intended recipient, please inform the sender by e-mail reply and
> destroy
> >  all copies of the original message.
> >
> >--
> >Ryan C. Decker '08
> >Sr. Network & Systems Engineer
> >Siena College ITS
> >515 Loudon Road
> >Loudonville, NY 12211
> >[11]rdec...@siena.edu
> >CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is
> for the
> >sole use of the intended 

Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread messju mohr

It's not strange, it's intended behaviour of the playground. See the "about" 
page of the playground:
"[...] In the playground the time begins at 2009-11-10 23:00:00 UTC 
(determining the significance of this date is an exercise for the reader). This 
makes it easier to cache programs by giving them deterministic output. [...]"


On Mon, May 08, 2017 at 10:22:14AM -0400, Decker, Ryan C. wrote:
>See here: [1]https://play.golang.org/p/EjdQRUnwQF
>The weird thing is that time.Now().UnixNano() doesn't appear to ever
>change in the playground...
>On Mon, May 8, 2017 at 10:21 AM, Decker, Ryan C. <[2]rdec...@siena.edu>
>wrote:
> 
>  I usually follow the example and go with time.Now().UnixNano() which you
>  can see here:
>  On Mon, May 8, 2017 at 10:07 AM, messju mohr
>  <[3]mes...@lammfellpuschen.de> wrote:
> 
>Hi,
> 
>in xrand() you are initialising r with the same constant seed for
>every call, so you always get the same pseudo random number.
> 
>See: <[4]https://play.golang.org/p/XwNmYv5nzJ>
> 
>cheers
>messju
> 
>On Mon, May 08, 2017 at 03:26:08AM -0700,
>[5]sivarajshabin...@gmail.com wrote:
>>    Hi All,
>>
>>    Firstly, sorry for the title that sounds like a click bait. I
>am not
>>    understanding what exactly is wrong with this program
>>    [1][6]https://play.golang.org/p/Tl0wpaCqK7
>>
>>    package main
>>
>>    import  (
>>        "fmt"
>>        "math/rand"
>>        "runtime"
>>    )
>>
>>    func xrand()  int  {
>>        r := rand.New(rand.NewSource(99))
>>        return r.Int()
>>    }
>>
>>    func main()  {
>>        fmt.Printf("Version %s\n", runtime.Version())
>>        fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n",
>xrand(), xrand(),
>>    xrand())
>>       
>>        r1 := rand.New(rand.NewSource(99))
>>        fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n",
>r1.Int(),
>>    r1.Int(), r1.Int())
>>    }
>>    Output
>>
>>  Version go1.8
>>  looks buggy     1: 1108929909, 2: 1108929909, 3: 1108929909
>>  Looks find      1: 1108929909, 2: 1298032409, 3: 913431059
>>
>>    When I generate a random number with "math/rand", like the
>example given
>>    in documentation [2][7]https://play.golang.org/p/O2k_za0AW7
>except that I
>>    return the randomly generated integer from a function, But the
>function
>>    keeps returning the same value any number of time I call it. On
>the
>>    contrary running the same code from the main generates random
>values,
>>    there isn't a reason to doubt rand package. However in the
>second print
>>    statement where random numbers are properly generated the first
>value
>>    always is the same value returned by xrand(), here there is
>something to
>>    doubt rand package.
>>
>>    What am I missing here?  Could it be a bug?
>>
>>    Thanks in advance.
>>
>>    Cheers
>>    Shabinesh
>--
>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 [8]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [9]https://groups.google.com/d/optout.
> 
>  --
>  Ryan C. Decker '08
>  Sr. Network & Systems Engineer
>  Siena College ITS
>  515 Loudon Road
>  Loudonville, NY 12211
>  [10]rdec...@siena.edu
>  CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is for
>  the sole use of the intended recipient(s) and may contain confidential
>  and privileged information. Any unauthorized review, use, disclosure, or
>  distribution is prohibited. If you received this e-mail and are not the
>  intended recipient, please inform the sender by e-mail reply and destroy
>  all copies of the original message.
> 
>--
>Ryan C. Decker '08
>Sr. Network & Systems Engineer
>Siena College ITS
>515 Loudon Road
>Loudonville, NY 12211
>[11]rdec...@siena.edu
>CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is for the
>sole use of the intended recipient(s) and may contain confidential and
>privileged information. Any unauthorized review, use, disclosure, or
>distribution is prohibited. If you received this e-mail and are not the
>intended recipient, please inform the sender by e-mail reply and destroy
>all copies of the original message.
> 
> References
> 
>Visible links
>1. 

Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread messju mohr
Hi,

in xrand() you are initialising r with the same constant seed for
every call, so you always get the same pseudo random number.

See: 

cheers
messju


On Mon, May 08, 2017 at 03:26:08AM -0700, sivarajshabin...@gmail.com wrote:
>Hi All,
> 
>Firstly, sorry for the title that sounds like a click bait. I am not
>understanding what exactly is wrong with this program
>[1]https://play.golang.org/p/Tl0wpaCqK7
> 
>package main
> 
>import  (
>    "fmt"
>    "math/rand"
>    "runtime"
>)
> 
>func xrand()  int  {
>    r := rand.New(rand.NewSource(99))
>    return r.Int()
>}
> 
>func main()  {
>    fmt.Printf("Version %s\n", runtime.Version())
>    fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n", xrand(), xrand(),
>xrand())
>   
>    r1 := rand.New(rand.NewSource(99))
>    fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n", r1.Int(),
>r1.Int(), r1.Int())
>}
>Output
> 
>  Version go1.8
>  looks buggy     1: 1108929909, 2: 1108929909, 3: 1108929909
>  Looks find      1: 1108929909, 2: 1298032409, 3: 913431059
> 
>When I generate a random number with "math/rand", like the example given
>in documentation [2]https://play.golang.org/p/O2k_za0AW7 except that I
>return the randomly generated integer from a function, But the function
>keeps returning the same value any number of time I call it. On the
>contrary running the same code from the main generates random values,
>there isn't a reason to doubt rand package. However in the second print
>statement where random numbers are properly generated the first value
>always is the same value returned by xrand(), here there is something to
>doubt rand package.
> 
>What am I missing here?  Could it be a bug?
> 
>Thanks in advance.
> 
>Cheers
>Shabinesh

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread 'chris dollin' via golang-nuts
 Every call of xrand calls .Int() on a fresh generator initialised
the same way as the previous one, so it will give the same
result. The calls to .Int() in main are all on the /same/
generator, which is updated by each call, so you get
three different values.

Chris



On 8 May 2017 at 11:26,   wrote:
> Hi All,
>
> Firstly, sorry for the title that sounds like a click bait. I am not
> understanding what exactly is wrong with this program
> https://play.golang.org/p/Tl0wpaCqK7
>
> package main
>
> import (
> "fmt"
> "math/rand"
> "runtime"
> )
>
> func xrand() int {
> r := rand.New(rand.NewSource(99))
> return r.Int()
> }
>
> func main() {
> fmt.Printf("Version %s\n", runtime.Version())
> fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n", xrand(), xrand(),
> xrand())
>
> r1 := rand.New(rand.NewSource(99))
> fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n", r1.Int(), r1.Int(),
> r1.Int())
> }
>
> Output
>
> Version go1.8
> looks buggy 1: 1108929909, 2: 1108929909, 3: 1108929909
> Looks find  1: 1108929909, 2: 1298032409, 3: 913431059
>
>
>
> When I generate a random number with "math/rand", like the example given in
> documentation https://play.golang.org/p/O2k_za0AW7 except that I return the
> randomly generated integer from a function, But the function keeps returning
> the same value any number of time I call it. On the contrary running the
> same code from the main generates random values, there isn't a reason to
> doubt rand package. However in the second print statement where random
> numbers are properly generated the first value always is the same value
> returned by xrand(), here there is something to doubt rand package.
>
> What am I missing here?  Could it be a bug?
>
> Thanks in advance.
>
> Cheers
> Shabinesh
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.



-- 
Chris "allusive" Dollin

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread Jan Mercl
On Mon, May 8, 2017 at 3:50 PM  wrote:

> Could it be a bug?

No, the xrand function will always return the same number.

-- 

-j

-- 
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.
For more options, visit https://groups.google.com/d/optout.