File: uint64_fallback.go

package info (click to toggle)
golang-golang-x-exp 0.0~git20181112.a3060d4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,968 kB
  • sloc: ansic: 1,884; sh: 342; objc: 273; asm: 48; makefile: 10
file content (21 lines) | stat: -rw-r--r-- 576 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !go1.9

package rand

// Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64.
func (pcg *PCGSource) Uint64() uint64 {
	pcg.multiply()
	pcg.add()
	// XOR high and low 64 bits together and rotate right by high 6 bits of state.
	return rotateLeft(pcg.high^pcg.low, -int(pcg.high>>58))
}

func rotateLeft(x uint64, k int) uint64 {
	const n = 64
	s := uint(k) & (n - 1)
	return x<<s | x>>(n-s)
}