b.ResetTimer() for i := 0; i < b.N; i++ { total += rnd.Next() + rnd.Next() } } func BenchmarkRand(b *testing.B) { r := rand.New(rand.NewSource(0x0ddc0ffeebadf00d)) b.ResetTimer() for i := 0; i < b.N; i++ { total += uint32(r.Int31()) } } func BenchmarkXorshift(b *testing.B) { r := xorshift.NewXorShift64Star(0x0ddc0ffeebadf00d) b.ResetTimer() for i := 0; i < b.N; i++ { total += uint32(r.Next()) } } var _ = rand.Source(&Rand{})
// Package crandsrc provides a source for math/rand via crypto/rand package crandsrc import ( crand "crypto/rand" "encoding/binary" mrand "math/rand" ) type Source struct{} func (s Source) Int63() int64 { var b [8]byte _, err := crand.Read(b[:]) if err != nil { // :( panic("no crypto source") } return int64(binary.LittleEndian.Uint64(b[:])) & 0x7fffffffffffffff } func (r Source) Seed(s int64) { // ignored } var _ = mrand.Source(Source{})