From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DEC0C433FE for ; Mon, 17 Oct 2022 20:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbiJQUnt convert rfc822-to-8bit (ORCPT ); Mon, 17 Oct 2022 16:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbiJQUnN (ORCPT ); Mon, 17 Oct 2022 16:43:13 -0400 Received: from ouvsmtp1.octopuce.fr (ouvsmtp1.octopuce.fr [194.36.166.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D120877E89; Mon, 17 Oct 2022 13:41:10 -0700 (PDT) Received: from panel.vitry.ouvaton.coop (unknown [194.36.166.20]) by ouvsmtp1.octopuce.fr (Postfix) with ESMTPS id 271301431; Mon, 17 Oct 2022 22:39:42 +0200 (CEST) Received: from sm.ouvaton.coop (ouvadm.octopuce.fr [194.36.166.2]) by panel.vitry.ouvaton.coop (Postfix) with ESMTPSA id E7C8B5E28B9; Mon, 17 Oct 2022 22:39:41 +0200 (CEST) MIME-Version: 1.0 Date: Mon, 17 Oct 2022 20:39:41 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT From: "Yann Droneaud" Message-ID: Subject: Re: [PATCH] random: use rejection sampling for uniform bounded random integers To: "Eric Biggers" , "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, sneves@dei.uc.pt In-Reply-To: References: <20221017023752.3907-1-Jason@zx2c4.com> X-Originating-IP: 10.0.20.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, 17 octobre 2022 à 20:27 "Eric Biggers" a écrit: > On Sun, Oct 16, 2022 at 08:37:53PM -0600, Jason A. Donenfeld wrote: > > > > > In order to be efficient, we implement a kernel-specific variant of > > Daniel Lemire's algorithm from "Fast Random Integer Generation in an > > Interval", linked below. The kernel's variant takes advantage of > > constant folding to avoid divisions entirely in the vast majority of > > cases, works on both 32-bit and 64-bit architectures, and requests a > > minimal amount of bytes from the RNG. > > > > Link: https://arxiv.org/pdf/1805.10941.pdf > > > > Thanks for doing this! Your code looks correct, but it was hard for me to > understand until I read the paper that is linked to. Other algorithms exists that might be easier to understand before the Lemire’s one. M.E. O’Neil has written a long blog post on many possible alternatives. https://www.pcg-random.org/posts/bounded-rands.html Regards. —- Yann Droneaud OPTEYA