File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,8 @@ func Uint32() (uint32, error) {
9090 // for 64-bits machines, doing 64 bits operations and then casting
9191 // should be faster than dealing with 32 bits operations
9292 r , err := Uint64 ()
93+ // 64 bits are sampled but only 32 bits are used. This does not affect the uniformity of the output
94+ // assuming that the 64-bits distribution is uniform
9395 return uint32 (r ), err
9496}
9597
@@ -102,7 +104,7 @@ func Uint32() (uint32, error) {
102104// - (random, nil) otherwise
103105func Uint32n (n uint32 ) (uint32 , error ) {
104106 r , err := Uint64n (uint64 (n ))
105- return uint32 (r ), err
107+ return uint32 (r ), err // `r` is less than `n` and necessarily fits in 32 bits
106108}
107109
108110// Uint returns a random uint.
You can’t perform that action at this time.
0 commit comments