by spacey on 5/1/24, 3:42 PM with 44 comments
by infogulch on 5/2/24, 12:06 AM
I recently found a super simple algorithm that appears to produce a number in the interval [0,N] with a branchless expression with a single multiplication in an extended number size. (Sorry I don't have a reference.)
Say you want to generate a number, G, in interval [0,N] where N<=UInt32Max. The algorithm is:
G = uint32( uint64(N)*uint64(rand.UInt32())>>32 )
It seems like this should select a number in the range with no bias. Is there something I missed?by rollulus on 5/2/24, 7:17 AM
by infogulch on 5/2/24, 1:36 AM
The end of the post they mention that an encoding/json/v2 package is in the works: https://github.com/golang/go/discussions/63397
by Smaug123 on 5/1/24, 8:55 PM
by skitter on 5/1/24, 11:05 PM
by lifthrasiir on 5/2/24, 5:02 AM
And even more ideally, as many v1 usages should be automatically fixed as possible by `go fix` or similar tools. Allowing this to all user packages would be a major improvement over the status quo.
by 38 on 5/3/24, 11:34 PM