aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/rand.go
blob: 958b95c22308ef158a97c6a85809517604c9322b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import "crypto/rand"

// TODO: make this a test in the crypto/rand package.

func main() {
	buf := make([]byte, 500)
	n, err := rand.Read(buf)
	if n != len(buf) || err != nil {
		println("could not read random numbers:", err)
	}

	// Very simple test that random numbers are at least somewhat random.
	sum := 0
	for _, b := range buf {
		sum += int(b)
	}
	if sum < 95*len(buf) || sum > 159*len(buf) {
		println("random numbers don't seem that random, the average byte is", sum/len(buf))
	} else {
		println("random number check was successful")
	}
}