| 20 | } |
| 21 | |
| 22 | func TestInt63n(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | |
| 25 | for i := 0; i < 20; i++ { |
| 26 | v, err := cryptorand.Int63n(100) |
| 27 | require.NoError(t, err, "unexpected error from Int63n") |
| 28 | t.Logf("value: %v <- random?", v) |
| 29 | require.GreaterOrEqual(t, v, int64(0), "values must be positive") |
| 30 | require.Less(t, v, int64(100), "values must be less than 100") |
| 31 | } |
| 32 | |
| 33 | // Ensure Int63n works for int larger than 32 bits |
| 34 | _, err := cryptorand.Int63n(1 << 35) |
| 35 | require.NoError(t, err, "expected Int63n to work for 64-bit int") |
| 36 | |
| 37 | // Expect a panic if max is negative |
| 38 | require.PanicsWithValue(t, "invalid argument to Int63n", func() { |
| 39 | cryptorand.Int63n(0) |
| 40 | }) |
| 41 | } |
| 42 | |
| 43 | func TestIntn(t *testing.T) { |
| 44 | t.Parallel() |