From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Yann Droneaud <ydroneaud@opteya.com>
Cc: Kees Cook <keescook@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Theodore Ts'o <tytso@mit.edu>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 3/5] random: add helpers for random numbers with given floor or range
Date: Mon, 14 Nov 2022 19:38:23 +0100 [thread overview]
Message-ID: <Y3KLH4FqFbJ7bfY0@zx2c4.com> (raw)
In-Reply-To: <60574e8f-20ff-0996-5558-e9bd35e42681@opteya.com>
On Mon, Nov 14, 2022 at 07:04:13PM +0100, Yann Droneaud wrote:
> I have a bad feeling about this one, and can't help but thinking it's going
> to bite someone: when asked to pick a number *between* 0 and 10,
> I usually think I'm allowed to pick 10 (even if I'm going to answer 7 as it should).
This is one of those bikeshed things you see all over the place, like
whether slices in a language should be [start index, end index] or
[start index, length], or whether arrays should be 0-based or 1-based.
We'll never settle this variety of dispute here.
But in this case, there are some particular reasons why it must be this
way. Firstly, usage of it this way matches most of the ways the function
is actually used in the kernel, and fits existing semantics. This alone
I find compelling. But also, having all of these functions use half-open
intervals means that each function can take care of its entire range,
without having to resort to using 64-bit arithmetic, and no function is
a complete subset of any other function. So doing it this way makes
these maximally useful too.
So anyway I think the function has to be defined like this. If you'd
like to bikeshed over a different name than "between", though, be my
guest. Maybe you'd like "from" better. But probably "between" is fine,
and with enough good examples (as my conversion patch does) and the
clear succinct documentation comment, we should be good.
Jason
next prev parent reply other threads:[~2022-11-14 18:38 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-22 1:43 [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}() Jason A. Donenfeld
2022-10-22 1:43 ` Jason A. Donenfeld
2022-10-22 1:43 ` Jason A. Donenfeld
2022-10-22 1:43 ` [PATCH v1 1/5] treewide: use get_random_u32_below() instead of deprecated function Jason A. Donenfeld
2022-10-22 1:43 ` Jason A. Donenfeld
2022-10-22 2:25 ` Darrick J. Wong
2022-10-22 2:25 ` Darrick J. Wong
2022-10-22 18:44 ` SeongJae Park
2022-10-22 18:44 ` SeongJae Park
2022-10-22 18:44 ` SeongJae Park
2022-10-22 1:44 ` [PATCH v1 2/5] prandom: remove prandom_u32_max() Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 1:44 ` [PATCH v1 3/5] random: add helpers for random numbers with given floor or range Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-11-14 18:04 ` Yann Droneaud
2022-11-14 18:38 ` Jason A. Donenfeld [this message]
2022-11-15 8:42 ` Yann Droneaud
2022-11-16 0:25 ` Jason A. Donenfeld
2022-10-22 1:44 ` [PATCH v1 4/5] treewide: use get_random_u32_{above,below}() instead of manual loop Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 1:44 ` [PATCH v1 5/5] treewide: use get_random_u32_between() when possible Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 1:44 ` Jason A. Donenfeld
2022-10-22 3:55 ` [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}() Jakub Kicinski
2022-10-22 3:55 ` Jakub Kicinski
2022-10-22 3:55 ` Jakub Kicinski
2022-10-22 4:23 ` Jason A. Donenfeld
2022-10-22 4:23 ` Jason A. Donenfeld
2022-10-22 4:23 ` Jason A. Donenfeld
2022-10-22 5:32 ` Jakub Kicinski
2022-10-22 5:32 ` Jakub Kicinski
2022-10-22 5:32 ` Jakub Kicinski
2022-10-22 5:47 ` Jason A. Donenfeld
2022-10-22 5:47 ` Jason A. Donenfeld
2022-10-22 5:47 ` Jason A. Donenfeld
2022-10-22 6:03 ` Jakub Kicinski
2022-10-22 6:03 ` Jakub Kicinski
2022-10-22 6:03 ` Jakub Kicinski
2022-10-23 21:07 ` Theodore Ts'o
2022-10-23 21:07 ` Theodore Ts'o
2022-10-23 21:07 ` Theodore Ts'o
2022-10-24 16:43 ` Jason A. Donenfeld
2022-10-24 16:43 ` Jason A. Donenfeld
2022-10-24 16:43 ` Jason A. Donenfeld
2022-10-22 10:21 ` Greg Kroah-Hartman
2022-10-22 10:21 ` Greg Kroah-Hartman
2022-10-22 10:21 ` Greg Kroah-Hartman
2022-10-24 16:37 ` Jason Gunthorpe
2022-10-24 16:37 ` Jason Gunthorpe
2022-10-24 16:37 ` Jason Gunthorpe
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=Y3KLH4FqFbJ7bfY0@zx2c4.com \
--to=jason@zx2c4.com \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=ydroneaud@opteya.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.