[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y3KLH4FqFbJ7bfY0@zx2c4.com>
Date: Mon, 14 Nov 2022 19:38:23 +0100
From: "Jason A. Donenfeld" <Jason@...c4.com>
To: Yann Droneaud <ydroneaud@...eya.com>
Cc: Kees Cook <keescook@...omium.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Herbert Xu <herbert@...dor.apana.org.au>,
Theodore Ts'o <tytso@....edu>, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 3/5] random: add helpers for random numbers with given
floor or range
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
Powered by blists - more mailing lists