From: Daniel Borkmann <dborkman@redhat.com>
To: Joe Perches <joe@perches.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Jakub Zawadzki <darkjames-ws@darkjames.pl>,
Eric Dumazet <eric.dumazet@gmail.com>,
Hannes Frederic Sowa <hannes@stressinduktion.org>
Subject: Re: [PATCH net-next 1/2] random32: add prandom_u32_lt_N and convert "misuses" of reciprocal_divide
Date: Thu, 16 Jan 2014 10:22:04 +0100 [thread overview]
Message-ID: <52D7A4BC.7080703@redhat.com> (raw)
In-Reply-To: <1389832172.14001.41.camel@joe-AO722>
On 01/16/2014 01:29 AM, Joe Perches wrote:
> On Thu, 2014-01-16 at 00:23 +0100, Daniel Borkmann wrote:
>> Many functions have open coded a function that return a random
>> number in range [0,N-1]. Also, only because we have a function
>> that is named reciprocal_divide(), it has not much to do with
>> the pupose where it is being used when a previous reciprocal_value()
>> has not been obtained.
>
> prandom_u32_lt_N?
>
> I do not like the camelcase name and thought the
> prandom_u32_max was better.
Hm, you wanted to have the name intuitive, right ... so
u32 prandom_u32_lt_N(u32 N) suggests "less then N". If you
are saying "_max" here, then you should keep in mind that
the maximum result you get from here is "max-1", not "max".
But whatever, it's just a name.
> How about using
>
> u32 prandom_u32_max(u32 max)
> {
> return (u32)(((u64)prandom_u32() * max) >> 32);
> }
>
> u32 prandom_u32_range(u32 a, u32 b)
> {
> if (b < a)
> swap(a, b);
>
> return a + (u32)(((u64)prandom_u32() * (b - a)) >> 32);
> }
I didn't introduce the last one as it wasn't used in the patch.
next prev parent reply other threads:[~2014-01-16 9:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-15 23:23 [PATCH net-next 0/2] reciprocal_divide updates Daniel Borkmann
2014-01-15 23:23 ` [PATCH net-next 1/2] random32: add prandom_u32_lt_N and convert "misuses" of reciprocal_divide Daniel Borkmann
2014-01-16 0:29 ` Joe Perches
2014-01-16 9:22 ` Daniel Borkmann [this message]
2014-01-16 3:14 ` Eric Dumazet
2014-01-16 9:28 ` David Laight
2014-01-16 9:30 ` Daniel Borkmann
2014-01-15 23:23 ` [PATCH net-next 2/2] reciprocal_divide: correction/update of the algorithm Daniel Borkmann
2014-01-16 0:17 ` Ben Hutchings
2014-01-16 0:46 ` Hannes Frederic Sowa
2014-01-16 3:07 ` Eric Dumazet
2014-01-16 10:26 ` Hannes Frederic Sowa
2014-01-16 16:37 ` Christoph Lameter
2014-01-16 17:24 ` Hannes Frederic Sowa
2014-01-17 10:05 ` David Laight
2014-01-16 18:50 ` Ben Hutchings
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=52D7A4BC.7080703@redhat.com \
--to=dborkman@redhat.com \
--cc=darkjames-ws@darkjames.pl \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=hannes@stressinduktion.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.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 NNTP newsgroup(s).