File tree 1 file changed +6
-6
lines changed
hypothesis-python/src/hypothesis/internal/conjecture
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -65,14 +65,14 @@ def draw_boolean(
65
65
if p >= 1 :
66
66
return True
67
67
68
- bits = math .ceil (- math .log2 (min (p , 1 - p )))
69
- # cap boolean draws at 8 bits so they are a constant size of one byte.
70
- # If a probability requires more than 8 bits to precisely represent,
68
+ # always use one byte for booleans to maintain constant draw size.
69
+ # If a probability requires more than 8 bits to represent precisely,
71
70
# the result will be slightly biased, but not badly.
72
- bits = min (bits , 8 )
73
-
71
+ bits = 8
74
72
size = 2 ** bits
75
- falsey = math .floor (size * (1 - p ))
73
+ # always leave at least one value that can be true, even for very small
74
+ # p.
75
+ falsey = max (1 , math .floor (size * (1 - p )))
76
76
n = self ._draw_bits (bits )
77
77
return n >= falsey
78
78
You can’t perform that action at this time.
0 commit comments