| 41 | } |
| 42 | |
| 43 | func TestIntn(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | |
| 46 | for i := 0; i < 20; i++ { |
| 47 | v, err := cryptorand.Intn(100) |
| 48 | require.NoError(t, err, "unexpected error from Intn") |
| 49 | t.Logf("value: %v <- random?", v) |
| 50 | require.GreaterOrEqual(t, v, 0, "values must be positive") |
| 51 | require.True(t, v < 100, "values must be less than 100") |
| 52 | } |
| 53 | |
| 54 | // Ensure Intn works for int larger than 32 bits |
| 55 | _, err := cryptorand.Intn(1 << 35) |
| 56 | require.NoError(t, err, "expected Intn to work for 64-bit int") |
| 57 | |
| 58 | // Expect a panic if max is negative |
| 59 | require.PanicsWithValue(t, "invalid argument to Intn", func() { |
| 60 | cryptorand.Intn(0) |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | func TestFloat64(t *testing.T) { |
| 65 | t.Parallel() |