Initial commit

Initial public review release v0.10.0
This commit is contained in:
alexvanin 2020-07-10 17:17:51 +03:00 committed by Stanislav Bogatyrev
commit dadfd90dcd
276 changed files with 46331 additions and 0 deletions

46
lib/rand/rand.go Normal file
View file

@ -0,0 +1,46 @@
package rand
import (
crand "crypto/rand"
"encoding/binary"
mrand "math/rand"
)
type cryptoSource struct{}
// Read is alias for crypto/rand.Read.
var Read = crand.Read
// New constructs the source of random numbers.
func New() *mrand.Rand {
return mrand.New(&cryptoSource{})
}
func (s *cryptoSource) Seed(int64) {}
func (s *cryptoSource) Int63() int64 {
return int64(s.Uint63())
}
func (s *cryptoSource) Uint63() uint64 {
buf := make([]byte, 8)
if _, err := crand.Read(buf); err != nil {
return 0
}
return binary.BigEndian.Uint64(buf)
}
// Uint64 returns a random uint64 value.
func Uint64(r *mrand.Rand, max int64) uint64 {
if max <= 0 {
return 0
}
var i int64 = -1
for i < 0 {
i = r.Int63n(max)
}
return uint64(i)
}