import (
"internal/buildcfg"
- "internal/race"
- "math/rand"
"sort"
"sync"
- "time"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
fieldtrack(pp.Text.From.Sym, fn.FieldTrack)
}
-func init() {
- if race.Enabled {
- rand.Seed(time.Now().UnixNano())
- }
-}
-
// StackOffset returns the stack location of a LocalSlot relative to the
// stack pointer, suitable for use in a DWARF location entry. This has nothing
// to do with its offset in the user variable.
import (
"bytes"
- "encoding/binary"
"errors"
prand "math/rand"
"testing"
}
func TestBatchedBuffering(t *testing.T) {
- var prandSeed [8]byte
- Read(prandSeed[:])
- prand.Seed(int64(binary.LittleEndian.Uint64(prandSeed[:])))
-
backingStore := make([]byte, 1<<23)
prand.Read(backingStore)
backingMarker := backingStore[:]
// the output of the random number generator when given a fixed seed.
func Example() {
- // Seeding with the same value results in the same random sequence each run.
- // For different numbers, seed with a different value, such as
- // time.Now().UnixNano(), which yields a constantly-changing number.
- rand.Seed(42)
answers := []string{
"It is certain",
"It is decidedly so",
"Very doubtful",
}
fmt.Println("Magic 8-Ball says:", answers[rand.Intn(len(answers))])
- // Output: Magic 8-Ball says: As I see it yes
}
// This example shows the use of each of the methods on a *Rand.
words[i], words[j] = words[j], words[i]
})
fmt.Println(words)
-
- // Output:
- // [mouth my the of runs corners from ink]
}
func ExampleShuffle_slicesInUnison() {
for i := range numbers {
fmt.Printf("%c: %c\n", letters[i], numbers[i])
}
-
- // Output:
- // C: 3
- // D: 4
- // A: 1
- // E: 5
- // B: 2
}
func ExampleIntn() {
- // Seeding with the same value results in the same random sequence each run.
- // For different numbers, seed with a different value, such as
- // time.Now().UnixNano(), which yields a constantly-changing number.
- rand.Seed(86)
fmt.Println(rand.Intn(100))
fmt.Println(rand.Intn(100))
fmt.Println(rand.Intn(100))
-
- // Output:
- // 42
- // 76
- // 30
}