git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Antriksh Pany <antriksh.pany@gmail.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
	gitster@pobox.com, git@vger.kernel.org, markus.heidelberg@web.de,
	jnareb@gmail.com
Subject: Re: [PATCH v3 1/2] compat: add a mkstemps() compatibility function
Date: Wed, 3 Jun 2009 16:33:36 -0700	[thread overview]
Message-ID: <20090603233335.GB8362@gmail.com> (raw)
In-Reply-To: <e6cd6cf90906030859m2725856cl77e210d87e261df0@mail.gmail.com>

On Wed, Jun 03, 2009 at 09:29:06PM +0530, Antriksh Pany wrote:
> Oh ok, didn't realize the sixth division was not used. In which case,
> we needn't have the sixth division.
> 
> Also, 62^5 compared to 2^32 still gives a ~ 21% probability of the
> fifth division becoming zero, fairly high perhaps.
> 
> The suggestion to change the code to
>    ((uint64_t) tv.tv_usec) << 16)
> might help here. This would still leave about a 1.4% chance of v
> becoming zero, higher than (being pedantic!) what perfect randomness
> would require. Livable. But (just curious), do we see any loss in
> shifting a few more positions?
> 
> - Antriksh


Just a small note -- our mkstemps was adapted from
libiberty's mkstemps.c (gcc-4.something), so if there is
indeed something to fix here then we should let them know.

I looked in libiberty since I assumed that the code in there
was battle-tested and stable.

I feel okay with it as-is, but that's just me.



> On Tue, Jun 2, 2009 at 6:35 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> > Antriksh Pany schrieb:
> >> 2. tv_usec has a decimal value range of 0-999999  (10^6 usec make 1
> >> sec). Which means that tv_usec fits completely in 20 bits (or less).
> >> (tv_usec << 16) yields a number that fits completely in 36 bits (or
> >> less). Max value of this number is 999999 * 2^16, or for convenience,
> >> about M = 10^6 * 2^16. This number (in the range of 0 to M) goes on to
> >> be divided by D=62^6. Also, M > D. Thus, there is about a  D / M * 100
> >> ~ 87 % probability of the division M / D working out to be zero. i.e,
> >> in 87% cases, the last division (v/= num_letters) will cause 'v' to
> >> become 0.
> >
> > But this value (after the 6th division, mind you) is not used. v is used
> > the last time after the 5th division; at this time it still carries enough
> > randomness: 62^5 < 2^32.
> >
> > -- Hannes
> >
> >

-- 
		David

      reply	other threads:[~2009-06-03 23:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-28  9:43 [PATCH v3 1/2] compat: add a mkstemps() compatibility function David Aguilar
2009-05-28  9:43 ` [PATCH v3 2/2] diff: generate prettier filenames when using GIT_EXTERNAL_DIFF David Aguilar
2009-06-02 12:35 ` [PATCH v3 1/2] compat: add a mkstemps() compatibility function Antriksh Pany
2009-06-02 13:05   ` Johannes Sixt
2009-06-03 15:59     ` Antriksh Pany
2009-06-03 23:33       ` David Aguilar [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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090603233335.GB8362@gmail.com \
    --to=davvid@gmail.com \
    --cc=antriksh.pany@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=jnareb@gmail.com \
    --cc=markus.heidelberg@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).