Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4995360rwi; Mon, 17 Oct 2022 13:57:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6W5pF6E3XsNwZhYmQCu1rhBr7efOekOMjHCQGOABOSYfje5GdQ/IDe2UFPsIhyoq05rv50 X-Received: by 2002:a65:63ce:0:b0:43a:2103:b7b8 with SMTP id n14-20020a6563ce000000b0043a2103b7b8mr12722598pgv.59.1666040222606; Mon, 17 Oct 2022 13:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666040222; cv=none; d=google.com; s=arc-20160816; b=hwDHFOjmZSzhZzOdT4B8U+yS6ey05sdMUcyiMUi2J+f5WeYfk7BalPJXv7X8TLpLZH twc0Oodtp550u0ccneuki18SMQX4NOeDCcWzg+wZXi+5O7mjyFHTMW4iRqAMHNiWw1yE Pel04TewEsoi8OLq7qc2sZKdouUzafc1noM94wqFVPXZhs0jJs6TSP7tNMAW3RnbBFXe NGS/Cy/DGWQvomz/noaV9XVnFOW30/rUhaNaDXwzUzXI5H1/P7QmDzvCEAVEc1jadg7c WIWw93ChCLS1TUia3hBmMW2rIWWvo3m72JDZkH9VdnI69D1LzggqzhLpfMCD0PFNHVZM mLxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:cc:to:subject:message-id :from:content-transfer-encoding:date:mime-version; bh=cLF8AgRbGtOImL/vUPZQAHgAouLfDAcLR7gTu3PJb6U=; b=XbJIEpM1V7X7QgQxV22cTsqF371jDGkPh+nPsk1sUC5lnfmYqiahafZcN/oWy1hdxn rRzv/y4c346q1bYQMWcIT96X6pLkaGoYrB1/4Q6+tKYUmBSXcmo4u5kcWBqpsgGxHFp6 yZrCEL73tGdJGQGAzQcCP50m3endVfLVzsTgd4+SOf67J55nN5FcCXf+ovsRKLXWCuH/ 43B9pfwRO/s/eewJ6dFbRVjj+Q3KkDxCsrDejsGqRH5vvfE+YJkVeYP8nET49cFnjEDT HVr/tBkIYjzCXV+7PBdKrmnMHhEJG6LQQyHCa0aP0wxg22TWGmRBKKEl5vZQPaFgA+4R dxIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a17090ad58300b00203336ddd4asi11406034pju.56.2022.10.17.13.56.50; Mon, 17 Oct 2022 13:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbiJQUns convert rfc822-to-8bit (ORCPT + 99 others); Mon, 17 Oct 2022 16:43:48 -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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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