Skip to content

Commit ba3e6ce

Browse files
authored
hotfix: remove cryptorand.Bool (#7780)
It caused a CI flake and we we weren't using it anywhere. `cryptorand.Float64() < 0.5` can be used in the future too.
1 parent 332362c commit ba3e6ce

File tree

3 files changed

+0
-36
lines changed

3 files changed

+0
-36
lines changed

cryptorand/errors_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ func TestRandError(t *testing.T) {
7575
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Float32 error")
7676
})
7777

78-
t.Run("Bool", func(t *testing.T) {
79-
_, err := cryptorand.Bool()
80-
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Bool error")
81-
})
82-
8378
t.Run("StringCharset", func(t *testing.T) {
8479
_, err := cryptorand.HexString(10)
8580
require.ErrorIs(t, err, io.ErrShortBuffer, "expected HexString error")

cryptorand/numbers.go

-11
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,6 @@ again:
185185
return f, nil
186186
}
187187

188-
// Bool returns a random true/false value as a bool.
189-
func Bool() (bool, error) {
190-
i, err := Uint64()
191-
if err != nil {
192-
return false, err
193-
}
194-
195-
// True if the least significant bit is 1
196-
return i&1 == 1, nil
197-
}
198-
199188
// Duration returns a random time.Duration value
200189
func Duration() (time.Duration, error) {
201190
i, err := Int63()

cryptorand/numbers_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,6 @@ func TestFloat32(t *testing.T) {
156156
}
157157
}
158158

159-
func TestBool(t *testing.T) {
160-
t.Parallel()
161-
162-
const iterations = 10000
163-
trueCount := 0
164-
165-
for i := 0; i < iterations; i++ {
166-
v, err := cryptorand.Bool()
167-
require.NoError(t, err, "unexpected error from Bool")
168-
if v {
169-
trueCount++
170-
}
171-
}
172-
173-
percentage := (float64(trueCount) / iterations) * 100
174-
t.Logf("number of true values: %d of %d total (%.2f%%)", trueCount, iterations, percentage)
175-
require.True(t, percentage > 48, "expected more than 48 percent of values to be true")
176-
require.True(t, percentage < 52, "expected less than 52 percent of values to be true")
177-
}
178-
179159
func TestDuration(t *testing.T) {
180160
t.Parallel()
181161

0 commit comments

Comments
 (0)