File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ func (r RNG) Uint16() uint16 {
31
31
return binary .LittleEndian .Uint16 (p [:])
32
32
}
33
33
34
- // Uintn generates a random uint in the interval [0, max).
34
+ // Uintn generates a random uint in the interval [0, max). It panics if
35
+ // max == 0.
35
36
func (r RNG ) Uintn (max uint ) uint {
36
37
bad := ^ uint (0 ) - ^ uint (0 )% max
37
38
x := uint (r .Uint64 ())
@@ -41,7 +42,7 @@ func (r RNG) Uintn(max uint) uint {
41
42
return x % max
42
43
}
43
44
44
- // Intn generates a random int in the interval [0, max). It panics if max < 0.
45
+ // Intn generates a random int in the interval [0, max). It panics if max <= 0.
45
46
func (r RNG ) Intn (max int ) int {
46
47
if max < 0 {
47
48
panic ("maximum below zero" )
@@ -51,7 +52,7 @@ func (r RNG) Intn(max int) int {
51
52
52
53
// Big generates a random number with maximum bit length nbits.
53
54
func (r RNG ) Big (nbits int ) * big.Int {
54
- p := make ([]byte , uint (nbits )>> 3 + uint ( nbits | nbits >> 1 | nbits >> 2 ) & 1 )
55
+ p := make ([]byte , ( uint (nbits )+ 7 ) >> 3 )
55
56
r .Read (p )
56
57
p [0 ] &= byte (0xff >> (8 - uint (nbits )& 7 ))
57
58
return new (big.Int ).SetBytes (p )
You can’t perform that action at this time.
0 commit comments