Skip to content

dolmen-go/shuffle-slice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

github.com/dolmen-go/shuffle-slice

Shuffle slices as you sort them.

Example:

package main

import (
    "github.com/dolmen-go/shuffle-slice/shuffle"
    "fmt"
    "sort"
)

func main() {
    slice := []string{"foo", "bar", "baz"}
    shuffle.Shuffle(sort.StringSlice(slice))
    fmt.Println(slice)
}

Note: since go1.10, the package math/rand has a function Shuffle:

package main

import (
    "fmt"
    "math/rand"
)

func main() {
    slice := []string{"foo", "bar", "baz"}
    rand.Shuffle(len(slice), func(i, j int) {
    	slice[i], slice[j] = slice[j], slice[i]
    })
    fmt.Println(slice)
}

About

Shuffle slices like with the 'sort' package

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages