amd64/121885: random() system call returning the same number
on amd64
Roland Smith
rsmith at xs4all.nl
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 xs4all.nl>
To: Lewis <lewis at elasticmind.net>
Cc: FreeBSD-gnats-submit at freebsd.org
Subject: Re: amd64/121885: random() system call returning the same number
on amd64
Date: Thu, 20 Mar 2008 13:45:57 +0100
--5/uDoXvLw7AC5HRs
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,
>=20
<snip> (please don't top-post)
>>> double r_num;
>>=20
>> This should be 'long r_num;', see random(3).
[fixed spelling :)]
>> With this change it works. Or, see below.
<snip>
>>> if (r_num < (percent / 100)) {
>>> printf("random: %u - Dropped packet.\n",r_num);
>>> } else {
>>> printf("random: %u - Sent packet.\n", r_num);
>>=20
>> 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.
<snip>
> 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=
on=20
> 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=
=20
> 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
/usr/src/sys/amd64/include/_types.h=20
I'll send you the source for a program that determines the lengths of
fundamental types off-list.
Roland
--=20
R.F.Smith http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
--5/uDoXvLw7AC5HRs
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.8 (FreeBSD)
iEYEARECAAYFAkfiXIUACgkQEnfvsMMhpyVx/QCgrkp+Vu1F6lh/rTOYWlva60PM
Y+IAniifAgWmij/grlvwWcWQCfr/7SOG
=+GrJ
-----END PGP SIGNATURE-----
--5/uDoXvLw7AC5HRs--
More information about the freebsd-amd64
mailing list