/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . Application Test-Random Description Simple test for sequence of random numbers \*---------------------------------------------------------------------------*/ #include "Rand48.H" #include "Random.H" #include #include #include #define TEST_RAW_IEEE // Construct a positive double with the 48 random bits distributed over // its fractional part so the resulting FP number is [0.0,1.0). // // As per glibc erand48() implementation #ifdef TEST_RAW_IEEE #include double randomFraction(const uint64_t bits) { // 48-bit value unsigned short int xsubi[3]; xsubi[0] = (bits & 0xffff); xsubi[1] = ((bits >> 16) & 0xffff); xsubi[2] = ((bits >> 32) & 0xffff); union ieee754_double temp; temp.ieee.negative = 0; temp.ieee.exponent = IEEE754_DOUBLE_BIAS; temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12); temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4); // The lower 4 bits of mantissa1 are always 0. return temp.d - 1.0; } #endif using namespace Foam; // Test uniformity of random void testPosition(const label n) { List