From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6175 Path: news.gmane.org!not-for-mail From: "Nadav Har'El" Newsgroups: gmane.linux.lib.musl.general Subject: Re: drand48() gives wrong sequence? Date: Sun, 21 Sep 2014 15:20:25 +0300 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c3d43ce0f8d60503925be0 X-Trace: ger.gmane.org 1411302044 9239 80.91.229.3 (21 Sep 2014 12:20:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Sep 2014 12:20:44 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6188-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 21 14:20:38 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XVg86-00069V-90 for gllmg-musl@plane.gmane.org; Sun, 21 Sep 2014 14:20:38 +0200 Original-Received: (qmail 24381 invoked by uid 550); 21 Sep 2014 12:20:37 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24373 invoked from network); 21 Sep 2014 12:20:37 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=LFhbZT2B3sJlwrpdpuPLTZZFOzZoh+nLCNyhsZMg60E=; b=MPGy6ah3gMq9EBtTdI6U7DbjuYlapuewG9+uVD5qStqDdxtTA6OMT2fvPMFfxnvMHE z1rWZWauXubGT+votfQDA3x7RvHupjMPcEJKhVOIW9Ip4EruGTdMQiSXTelzA9dz6w5G 4waDIKBidKlo3Yn22xKhAqOyMe7JiDYAh9JokJnm1NOcWlOnBtpbP4Kdis9N85uPdWd/ GV2F97tgzLFKLocBuJM7G6GR6O4E8T2qN6DsiadL+eRPxQUY3YKBn5XuYrQiklueiSEv V6YEIf2r0V1Ox0cZd5vnWfaGpKVE6ihrK1XlNK11fe1DC7kuOOAGbn12e4rKvP772wwJ XeMg== X-Gm-Message-State: ALoCoQn5/YkryVOwuDeiKhoN4VCk9O1r0hHIKGirtFNYCH9DQJ0GRsF1gNDTvNCDlRDkLQds59qk X-Received: by 10.70.129.72 with SMTP id nu8mr18878261pdb.91.1411302025126; Sun, 21 Sep 2014 05:20:25 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:6175 Archived-At: --001a11c3d43ce0f8d60503925be0 Content-Type: text/plain; charset=UTF-8 >Am Sonntag, den 21.09.2014, 14:45 +0300 schrieb Nadav Har'El: >> Any ideas why I'm getting the wrong sequence? > >I don't think you are getting the wrong sequence, you are just >printing it wrong. "%ld" is for long double and not for double. > >Jens (I tried to subscribe to the mailing list but it didn't work, so please CC me with further responses). "%ld" is not a double at all, it's an int. My message's title was indeed somewhat confusing, because I mentioned drand48() in the title but used lrand48() in my example code. I saw the same problem of a different sequence also with drand48() (printed with %g of course) - but at the end decided to include code which printed lrand48(). Anyway, "%ld" is the right thing to use here because lrand48() returns a "long int". Replacing it with "%d" makes no difference and the sequences are still different (I tried). This is because while lrand48()'s type is officially "long", its return value is just 32-bit, so one can treat it just fine as either long (64-bit on my 64-bit machine) or int (32-bit) and you get the same result. -- Nadav Har'El nyh@cloudius-systems.com --001a11c3d43ce0f8d60503925be0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
&g=
t;Am Sonntag, den 21.09.2014, 14:45 +0300 schrieb Nadav Har'El:
>> Any ideas why I'm getting the wrong sequence?
>
>I don't think you are getting the wrong sequence, you are just
>printing it wrong. "%ld" is for long double and not for doubl=
e.
>
>Jens
(I tried to subscribe to the mailing list but it didn't work, so = please CC me with further responses).

"%ld" is not a= double at all, it's an int.

My message's title was in= deed somewhat confusing, because I mentioned drand48() in the title but use= d lrand48() in my example code. I saw the same problem of a different seque= nce also with drand48() (printed with %g of course) - but at the end decide= d to include code which printed lrand48().

Anyway, "%ld&q= uot; is the right thing to use here because lrand48() returns a "long = int".
Replacing it with "%d" makes no difference an= d the sequences are still different (I tried). This is because while lrand4= 8()'s type is officially "long", its return value is just 32-= bit, so one can treat it just fine as either long (64-bit on my 64-bit mach= ine) or int (32-bit) and you get the same result.


--
Nadav Har'El<= br>
nyh@= cloudius-systems.com
--001a11c3d43ce0f8d60503925be0--