Hacker News new | ask | show | jobs
by Vendan 3021 days ago
Fun fact: the crypto rand "number" benchmark depends on the number you pass into it:

    BenchmarkCryptoRand27-8   	 5000000	       388 ns/op
    BenchmarkCryptoRand28-8   	 3000000	       356 ns/op
    BenchmarkCryptoRand29-8   	 5000000	       335 ns/op
    BenchmarkCryptoRand30-8   	 5000000	       327 ns/op
    BenchmarkCryptoRand31-8   	 5000000	       331 ns/op
    BenchmarkCryptoRand32-8   	 5000000	       322 ns/op
    BenchmarkCryptoRand33-8   	 3000000	       480 ns/op
    BenchmarkCryptoRand34-8   	 3000000	       474 ns/op
for benchmarks like

    func BenchmarkCryptoRand32(b *testing.B) {
        for n := 0; n < b.N; n++ {
            _, err := crand.Int(crand.Reader, big.NewInt(32))
            if err != nil {
                panic(err)
            }
        }
    }
This is because the crypto/rand library is very very careful to give you unbiased random numbers.