FAQ
Is there an idiomatic way to set the random number seed if we want a
different one for every one (some specific call to the time or something)?
I realize there are different ways one could do it, and there are sometimes
specific considerations, but I'm just wondering if there is a "standard"
way to do it

On Wednesday, May 16, 2012 10:42:39 AM UTC-7, minux wrote:


On Thu, May 17, 2012 at 1:32 AM, hs <happy...@gmx.de <javascript:>> wrote:
On Apr 2, 11:43 am, minux wrote:
I think the main reason for a default seed is reproducibility.
I need exactly this: Random numbers which will be the same across all
supported platforms.

Will I achieve this by using a fixed seed?
Yes. But you don't need to do this yourself, as the default random source
for
math/rand uses 1 as initial seed.
http://golang.org/src/pkg/math/rand/rand.go#L114
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Scott Pakin at Feb 8, 2013 at 1:37 am

    On Monday, April 2, 2012 9:04:22 AM UTC-6, Alex wrote:

    I observe strange behavior. Seems pseudo random generator is indeed
    very pseudo. It generates same set of values on every program run. Try
    following:
    http://play.golang.org/p/3Syxa7YJr9

    Run this code several times and you will be same sequence of values
    every time, I think this is not normal. Is this a bug?

    http://dilbert.com/strips/comic/2001-10-25/

    :-)

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • John Nagle at Feb 9, 2013 at 2:41 am

    On 2/7/2013 5:37 PM, Scott Pakin wrote:
    On Monday, April 2, 2012 9:04:22 AM UTC-6, Alex wrote:

    I observe strange behavior. Seems pseudo random generator is indeed
    very pseudo. It generates same set of values on every program run. Try
    following:
    http://play.golang.org/p/3Syxa7YJr9

    Run this code several times and you will be same sequence of values
    every time, I think this is not normal. Is this a bug?
    It's a feature of the Go Playground. The start time for
    all Playground programs is the same, to make the Playground
    deterministic.

    John Nagle

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Russ Cox at Feb 8, 2013 at 9:48 am

    On Thu, Feb 7, 2013 at 6:59 PM, Brendan Tracey wrote:

    Is there an idiomatic way to set the random number seed if we want a
    different one for every one (some specific call to the time or something)?
    I realize there are different ways one could do it, and there are sometimes
    specific considerations, but I'm just wondering if there is a "standard"
    way to do it
    rand.Seed(time.Now().UnixNano()) is as good as anything else.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 7, '13 at 11:59p
activeFeb 9, '13 at 2:41a
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase