This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libgfortran,patch] Scramble bytes in the user-provided random seeds (PR 32812)
- From: FX Coudert <fxcoudert at gmail dot com>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches list <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 25 Feb 2008 08:45:03 +0000
- Subject: [libgfortran,patch] Scramble bytes in the user-provided random seeds (PR 32812)
Hi all,
Current library implementation of RANDOM_NUMBER() is such that the
highest bits of the user-provided seed determine the mots significant
bits of floating-points values return, and the lowest bits of the
seed control the least significant bits of fp values. Thus, a user
providing us with a seed with good lower bits but poor higher bits
will find that the fp values are not very random at all... one such
example being the use of DATE_AND_TIME to provide for random seeds.
This patch adds a little to the quality of implementation by adding a
(bijective) scrambling operation between the seed the user gives us
and the seed we actually use. Two functions, scramble_seed and
unscramble_seed, are used when RANDOM_NUMBER() is called with a PUT=
or GET= argument, which shuffles bytes of the seed.
Regtested on x86_64-linux, with both -m32 and -m64. Tested manually
with different seeds of different qualities.
FX
PS: Of course, we're not adding quality to poor seeds (I'm not
changing entropy with a bijective function!). We're just providing a
little invisible help to one particular case of half-bad, half-good
seeds.
--
François-Xavier Coudert
http://www.homepages.ucl.ac.uk/~uccafco/
Attachment:
random.ChangeLog
Description: Binary data
Attachment:
random.diff
Description: Binary data