package shuffle
import "github.com/shogo82148/go-shuffle"
Package shuffle provides primitives for shuffling slices and user-defined collections.
As of Go 1.10, the same functionality is now provided by package math/rand, and those implementations should be preferred in new code.
Index ¶
- func Float64s(a []float64)
- func Int64s(a []int64)
- func Ints(a []int)
- func Shuffle(data Interface)
- func Slice(slice interface{})
- func SortInt64s(a []int64)
- func Strings(a []string)
- type Int64Slice
- func (p Int64Slice) Len() int
- func (p Int64Slice) Less(i, j int) bool
- func (p Int64Slice) Swap(i, j int)
- type Interface
- type Shuffler
Examples ¶
Functions ¶
func Float64s ¶
func Float64s(a []float64)
Float64s shuffles a slice of float64s.
func Int64s ¶
func Int64s(a []int64)
Int64s shuffles a slice of int64s.
func Ints ¶
func Ints(a []int)
Ints shuffles a slice of ints.
Code:
Output:Example¶
{
x := []int{1, 2, 3, 4, 5}
shuffle.Ints(x)
for _, value := range x {
fmt.Println(value)
// Unordered output:
// 1
// 2
// 3
// 4
// 5
}
}
1
2
3
4
5
func Shuffle ¶
func Shuffle(data Interface)
Shuffle shuffles Data.
As of Go 1.10, it just calls rand.Shuffle(data.Len(), data.Swap).
func Slice ¶
func Slice(slice interface{})
Slice shuffles the slice.
func SortInt64s ¶
func SortInt64s(a []int64)
SortInt64s sorts a slice of int64s in increasing order.
func Strings ¶
func Strings(a []string)
Strings shuffles a slice of strings.
Types ¶
type Int64Slice ¶
type Int64Slice []int64
Int64Slice attaches the methods of Interface to []int64, sorting in increasing order.
func (Int64Slice) Len ¶
func (p Int64Slice) Len() int
func (Int64Slice) Less ¶
func (p Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (p Int64Slice) Swap(i, j int)
type Interface ¶
type Interface interface { // Len is the number of elements in the collection. Len() int // Swap swaps the elements with indexes i and j. Swap(i, j int) }
Interface is a type, typically a collection, that satisfies shuffle.Interface can be shuffled by the routines in this package.
type Shuffler ¶
A Shuffler provides Shuffle
func New ¶
New returns a new Shuffler that uses random values from src to shuffle
func (*Shuffler) Float64s ¶
Float64s shuffles a slice of float64s.
func (*Shuffler) Ints ¶
Ints shuffles a slice of ints.
func (*Shuffler) Shuffle ¶
Shuffle shuffles Data.
As of Go 1.10, it just calls (*rand.Rand).Shuffle(data.Len(), data.Swap).
func (*Shuffler) Slice ¶
func (s *Shuffler) Slice(slice interface{})
Slice shuffles the slice.
func (*Shuffler) Strings ¶
Strings shuffles a slice of strings.
Source Files ¶
interface.go shuffle.go shuffle_slice.go
- Version
- v1.1.1 (latest)
- Published
- Aug 14, 2024
- Platform
- windows/amd64
- Imports
- 3 packages
- Last checked
- now –
Tools for package owners.