random

package
v0.0.0-...-89aa834 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shuffle

func Shuffle[R Uint64NGenerator, S ~[]T, T any](r R, s S) S

Shuffle randomly shuffles the elements in the slice.

func ShuffleN

func ShuffleN[R Uint64NGenerator, S ~[]T, T any](r R, s S, n int) S

ShuffleN randomly selects and shuffles the first n elements from the entire slice. It ensures that the first n elements are randomly chosen from the whole slice, not just shuffled among themselves. Elements after the nth position may also be affected. This differs from a complete shuffle as it only guarantees randomness for the first n elements. It panics if n is negative or greater than the length of the slice.

Types

type Uint64NGenerator

type Uint64NGenerator interface {
	Uint64N(n uint64) uint64
}

Uint64NGenerator is an interface for generating random uint64 numbers in the range [0, n).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL