From: Paul Eggert <eggert@cs.ucla.edu>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] stdlib: Simplify arc4random_uniform
Date: Thu, 28 Jul 2022 13:35:07 -0700 [thread overview]
Message-ID: <e7cd5f54-4706-6b7c-2f91-83385a8297d1@cs.ucla.edu> (raw)
In-Reply-To: <20220728124528.39169-1-adhemerval.zanella@linaro.org>
On 7/28/22 05:45, Adhemerval Zanella via Libc-alpha wrote:
> It uses the bitmask with rejection [1], which calculates a mask
> being the lowest power of two bounding the request upper bound,
> successively queries new random values, and rejects values
> outside the requested range.
>
> Performance-wise, there is no much gain in trying to converse
converse -> conserve
> bits since arc4random is wrapper on getrandom syscall. It should
> be cheaper to just query a uint32_t value. The algorithm also
> avoids mudulo and divide operations, which might be costly
mudulo -> modulo
> + int bits_left = z;
> + while (bits_left >= bits)
> + {
...
> + bits_left -= bits;
> + }
Clearer would be "for (int bits_left = z; bits_left >= bits; bits_left
-= bits)".
Looks good otherwise; thanks.
prev parent reply other threads:[~2022-07-28 20:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-28 12:45 Adhemerval Zanella
2022-07-28 14:46 ` Yann Droneaud
2022-07-28 14:58 ` Adhemerval Zanella Netto
2022-07-28 20:35 ` Paul Eggert [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e7cd5f54-4706-6b7c-2f91-83385a8297d1@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).