Examples using... "math/rand"
Recent
This example shows the use of each of the methods on a *Rand.
The use of the global functions is the same, without the receiver.
Package rand implements pseudo-random number generators.
Shuffle pseudo-randomizes the order of elements using the default Source.
n is the number of elements. Shuffle panics if n < 0.
swap swaps the elements with indexes i and j.
Shuffle pseudo-randomizes the order of elements using the default Source.
n is the number of elements. Shuffle panics if n < 0.
swap swaps the elements with indexes i and j.
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n)
from the default Source.
Intn returns, as an int, a non-negative pseudo-random number in [0,n)
from the default Source.
It panics if n <= 0.
Go’s math/rand package provides pseudorandom number generation.
Here we use the built-in synchronization features of goroutines and channels to achieve synchronized access to shared state. This channel-based approach aligns with Go’s ideas of sharing memory by communicating and having each piece of data owned by exactly 1 goroutine.