[PATCH, libstdc++] Improve the performance of std::uniform_int_distribution (fewer divisions)

Jonathan Wakely jwakely@redhat.com
Tue Oct 6 20:04:41 GMT 2020


On 06/10/20 15:55 -0400, Daniel Lemire via Libstdc++ wrote:
>The updated patch looks good to me. It is indeed cleaner to have a separate
>(static) function.
>
>It might be nice to add a comment to explain the _S_nd function maybe with
>a comment like "returns a random value in [0,__range)
>without any bias" (or something to that effect).

Indeed. My current local branch has this comment on _S_nd:

+      // Lemire's nearly divisionless algorithm.
+      // Returns a random number from __g downscaled to [0,__range)
+      // using an unsigned type _Wp twice as wide as unsigned type _Up.

I think "Returns an unbiased random number from ..." would be an
improvement.

>Otherwise, it is algorithmically correct.

Great, thanks for the review.

I'll get it committed tomorrow then. Thanks for the patch, and sorry
it took so long.



More information about the Gcc-patches mailing list