diff options
author | Steve <nilslice@gmail.com> | 2016-10-19 13:54:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-19 13:54:40 -0700 |
commit | c33b9254cb890b7137aa0cae31bd1c3311d902e7 (patch) | |
tree | 1dbf58f4e594a6c8a9f897a76a0255ec19d8fb47 /cmd/ponzu/vendor/github.com/nilslice/rand/rand.go | |
parent | 46bf18fe0e6d80e25d44f1f4e6c3094e8977074a (diff) | |
parent | d10db9f1799976aee60254dd7c73e73cf019ca6c (diff) |
Merge pull request #5 from bosssauce/ponzu-dev
[dependency] Vendor all dependencies
Diffstat (limited to 'cmd/ponzu/vendor/github.com/nilslice/rand/rand.go')
m--------- | cmd/ponzu/vendor/github.com/nilslice/rand | 0 | ||||
-rw-r--r-- | cmd/ponzu/vendor/github.com/nilslice/rand/rand.go | 38 |
2 files changed, 38 insertions, 0 deletions
diff --git a/cmd/ponzu/vendor/github.com/nilslice/rand b/cmd/ponzu/vendor/github.com/nilslice/rand deleted file mode 160000 -Subproject 7bcefe633d436bb68eb327d81e47c255203a897 diff --git a/cmd/ponzu/vendor/github.com/nilslice/rand/rand.go b/cmd/ponzu/vendor/github.com/nilslice/rand/rand.go new file mode 100644 index 0000000..cbff54a --- /dev/null +++ b/cmd/ponzu/vendor/github.com/nilslice/rand/rand.go @@ -0,0 +1,38 @@ +// rand provides a convenient package to use crypto/rand as default +// but falls back to math/rand if necessary +package rand + +import ( + crand "crypto/rand" + mrand "math/rand" + "time" +) + +var g_mathRand = mrand.New(mrand.NewSource(time.Now().Unix())) + +// Read fills the slice with random bytes +func Read(xs []byte) { + length := len(xs) + n, err := crand.Read(xs) + if n != length || err != nil { + for length > 0 { + length-- + xs[length] = byte(g_mathRand.Int31n(256)) + } + } +} + +// Int63 returns a non-negative 63-bit integer as an int64 +func Int63() int64 { + xs := make([]byte, 8) + var n int64 + + Read(xs) + xs[0] &= 0x7F + for _, x := range xs { + n <<= 4 + n |= int64(x) + } + + return n +} |