Re: [go-nuts] Shuffle Items in a Slice

2016-06-26 Thread Martin Geisler
On Fri, Jun 24, 2016 at 2:54 PM, Val wrote: > The playground caches everything, so running multiple times the same program > will just serve the previously generated output. Thanks, that's good to know! Makes a lot of sense too. > Also in the playground everything is frozen at some point in the

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Joubin Houshyar
On Friday, June 24, 2016 at 1:16:12 PM UTC-4, Joubin Houshyar wrote: > > > On Friday, June 24, 2016 at 7:39:23 AM UTC-4, Konstantin Khomoutov wrote: >> >> On Fri, 24 Jun 2016 04:05:49 -0700 (PDT) >> dc0d wrote: >> >> > To shuffle items in a slice I'm doing this: >> > >> > var res []Item >>

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Joubin Houshyar
On Friday, June 24, 2016 at 7:39:23 AM UTC-4, Konstantin Khomoutov wrote: > > On Fri, 24 Jun 2016 04:05:49 -0700 (PDT) > dc0d > wrote: > > > To shuffle items in a slice I'm doing this: > > > > var res []Item > > > > //fill res logic > > > > shuffle := make(map[int]*Item) > > for k, v := r

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Thanks Val for explanation & clarification; On Friday, June 24, 2016 at 5:24:30 PM UTC+4:30, Val wrote: > > The playground caches everything, so running multiple times the same > program will just serve the previously generated output. > > Also in the playground everything is frozen at some point

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Martin Geisler
On Fri, Jun 24, 2016 at 1:05 PM, dc0d wrote: > > Hi; > > To shuffle items in a slice I'm doing this: > > var res []Item > > //fill res logic > > shuffle := make(map[int]*Item) > for k, v := range res { > shuffle[k] = &v > } > res = nil > for _, v := range shuffle { > res = append(res, *v) > } >

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Val
The playground caches everything, so running multiple times the same program will just serve the previously generated output. Also in the playground everything is frozen at some point in the past : the clock, the randomness sources, and you can't make outgoing requests to import randomness from

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Kaveh Shahbazian
Thanks Martin for the clarification! Yet this inconsistent behavior is daunting. What version of Go is playground using? x86? GopherJS? Better be something wrong with playground! :) On Fri, Jun 24, 2016 at 5:08 PM Martin Geisler wrote: > On Fri, Jun 24, 2016 at 1:05 PM, dc0d wrote: > > > > Hi;

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Please explain what other properties are you referring to? I'm using this to choose from a list of tickets/tokens from database to reduce contention (CouchDB). So being cryptographic is not a concern here but rather being fast. And if I'm not mistaken package rand uses a mutex internally - I th

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Jan Mercl
map ranging randomization has to be fast - at the cost of the randomization other properties. Use instead perhaps https://golang.org/pkg/math/rand/#Rand.Perm to get a random slice of indexes of a proper length. Later range that slice instead and indirectly use the original slice item at the particu

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 04:05:49 -0700 (PDT) dc0d wrote: > To shuffle items in a slice I'm doing this: > > var res []Item > > //fill res logic > > shuffle := make(map[int]*Item) > for k, v := range res { > shuffle[k] = &v > } > res = nil > for _, v := range shuffle { > res = append(res, *v) > }

[go-nuts] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Hi; To shuffle items in a slice I'm doing this: var res []Item //fill res logic shuffle := make(map[int]*Item) for k, v := range res { shuffle[k] = &v } res = nil for _, v := range shuffle { res = append(res, *v) } Which inserts items into a map then ranges over that map. Ranging over a map