trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tyson.w.smith@gmail.com
To: davej@codemonkey.org.uk
Cc: trinity@vger.kernel.org, tysmith@motorola.com,
	Tyson Smith <tyson.w.smith@gmail.com>
Subject: [PATCH 3/7] simplify most significant byte modification statement
Date: Mon, 16 Mar 2015 13:26:02 -0700	[thread overview]
Message-ID: <1426537562-54874-1-git-send-email-tyson.w.smith@gmail.com> (raw)

From: Tyson Smith <tyson.w.smith@gmail.com>

---
 random.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/random.c b/random.c
index 7917f78..8b4f715 100644
--- a/random.c
+++ b/random.c
@@ -171,15 +171,9 @@ u64 rand64(void)
 	if (ONE_IN(25))
 		r = ~r;
 
-	/* increase distribution in MSB */
-	if (ONE_IN(10)) {
-		unsigned int i;
-		unsigned int rounds;
-
-		rounds = rand() % 4;
-		for (i = 0; i < rounds; i++)
-			r |= (1UL << ((__WORDSIZE - 1) - (rand() % 8)));
-	}
+	/* Set ~2 bits in MSB to increase distribution */
+	if (ONE_IN(10))
+		r |= (rand() & rand() & 0xffULL) << 56;
 
 	/* Sometimes flip sign */
 	if (ONE_IN(25))
-- 
1.9.1

                 reply	other threads:[~2015-03-16 20:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1426537562-54874-1-git-send-email-tyson.w.smith@gmail.com \
    --to=tyson.w.smith@gmail.com \
    --cc=davej@codemonkey.org.uk \
    --cc=trinity@vger.kernel.org \
    --cc=tysmith@motorola.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 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).