amd64/121885: random() system call returning the same number on amd64

Roland Smith rsmith at
Thu Mar 20 12:50:03 UTC 2008

The following reply was made to PR amd64/121885; it has been noted by GNATS.

From: Roland Smith <rsmith at>
To: Lewis <lewis at>
Cc: FreeBSD-gnats-submit at
Subject: Re: amd64/121885: random() system call returning the same number
	on amd64
Date: Thu, 20 Mar 2008 13:45:57 +0100

 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 On Thu, Mar 20, 2008 at 11:03:28AM +0000, Lewis wrote:
 > Hi,
 <snip> (please don't top-post)
 >>> 	double r_num;
 >> This should be 'long r_num;', see random(3).
 [fixed spelling :)]
 >> With this change it works. Or, see below.
 >>> 		if (r_num < (percent / 100)) {
 >>> 			printf("random: %u - Dropped packet.\n",r_num);
 >>> 		} else {
 >>> 			printf("random: %u - Sent packet.\n", r_num);
 >> And if you want to use doubles, you should have used '%f' of '%g' here,
 >> instead of '%u'. In which case it works as well.
 > Thanks for looking at this and spotting the problem, so much time was=20
 > wasted trying to figure out what was wrong :( I guess much of the confusi=
 > was caused by the same code working on i386 but not amd64 and is what=20
 > prompted people to suggest to me writing a PR. Would it have been because=
 > amd64 uses different sizes of 'double' than i386 or something like that?
 I think it is rather the size of 'long', which is 32 bits on i386 and 64
 bits on amd64. Compare /usr/src/sys/i386/include/_types.h and
 I'll send you the source for a program that determines the lengths of
 fundamental types off-list.
 [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
 pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 Version: GnuPG v2.0.8 (FreeBSD)

More information about the freebsd-amd64 mailing list