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 thing that can be ignored compared to other tasks at hand (IO, db, disk) though; and thanks for mentioning Perm! Yet again you can range over a map concurrently in a read-only manner - randomized for free! I've not tried/take a look at crypto/rand yet. On Friday, June 24, 2016 at 4:16:47 PM UTC+4:30, Jan Mercl wrote: > > 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 particular index fetched from the first > slice. > > On Fri, Jun 24, 2016, 13:05 dc0d <kaveh.sh...@gmail.com <javascript:>> > 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) >> } >> >> Which inserts items into a map then ranges over that map. Ranging over a >> map in Go returns the items in random order. >> >> 1 - I thought it's a cool trick! >> 2 - Is anything bad about doing this? >> >> -- >> 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...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- > > -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.