Thank you all for replying. I get it now. On 8 May 2017 8:20 pm, "messju mohr" <mes...@lammfellpuschen.de> 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 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. https://play.golang.org/p/EjdQRUnwQF > > 2. mailto:rdec...@siena.edu > > 3. mailto:mes...@lammfellpuschen.de > > 4. https://play.golang.org/p/XwNmYv5nzJ > > 5. mailto:sivarajshabin...@gmail.com > > 6. https://play.golang.org/p/Tl0wpaCqK7 > > 7. https://play.golang.org/p/O2k_za0AW7 > > 8. mailto:golang-nuts%2bunsubscr...@googlegroups.com > > 9. https://groups.google.com/d/optout > > 10. mailto:rdec...@siena.edu > > 11. mailto:rdec...@siena.edu > -- 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.