/usr/include/linbox/randiter/gmp-rational.h is in liblinbox-dev 1.4.2-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | /* linbox/randiter/gmp-rational.h
* Copyright (C) 2001-2002 Bradford Hovinen
*
* Written by William J Turner <wjturner@acm.org>,
* Bradford Hovinen <hovinen@cis.udel.edu>
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
/*! @file randiter/gmp-rational.h
* @ingroup randiter
* @brief Generate a random rational with prescribed size.
*/
#ifndef __LINBOX_randiter_gmp_rational_H
#define __LINBOX_randiter_gmp_rational_H
#include "linbox/field/gmp-rational.h"
#include "linbox/element/gmp-rational.h"
#include "linbox/element/abstract.h"
#include "linbox/element/envelope.h"
#include "linbox/linbox-config.h"
#include <sys/time.h>
#include <stdlib.h>
namespace LinBox
{
class GMPRationalRandIter {
public:
/// Element type.
typedef GMPRationalElement Element;
/*! Rational number random iterator.
* @ingroup rationals
* @ingroup randiter
*
* @param F rational field
* @param size ??.
* @param seed seed for random generator. By default it is 0
* and a new one is created.
*/
GMPRationalRandIter (const GMPRationalField &F,
const integer &size = 0,
const integer &seed = 0) :
_field (F), _size (size), _seed (seed)
{
if (seed == 0)
_seed = uint32_t(time (NULL));
}
/// Copy constructor
/// @param R Random iterator to copy.
GMPRationalRandIter (const GMPRationalRandIter& R) :
_field (R._field), _size (R._size), _seed (R._seed)
{}
/// Destructor.
~GMPRationalRandIter()
{}
/*! Copy.
* @param R Random iterator to copy.
* @return a reference to this copy.
*/
GMPRationalRandIter& operator=(const GMPRationalRandIter& R)
{
if (this != &R) { // guard against self-assignment
_field = R._field;
_seed = R._seed;
_size = R._size;
}
return *this;
}
/*! get a random number.
* @param[out] a a random rational.
*/
Element &random (Element &a) const
{
if (_size == 0) {
unsigned int s;
s = _seed;
//(rand_r is obsolete)
srand (s);
int value = rand();
mpz_set_si (mpq_numref (a.rep), value);
do {
value = rand();
} while (value == 0);
const_cast<integer&>(_seed) = s;
mpz_set_si (mpq_denref (a.rep), value);
}
else {
unsigned int s;
int num, den;
s = _seed;
srand (s);
num = rand();
if (_size > 0) {
int tmp = (int)_size;
num %= tmp;
den = 1L;
}
else {
srand (s);
den = rand();
}
const_cast<integer&>(_seed) = s;
mpz_set_si (mpq_numref (a.rep), num);
mpz_set_si (mpq_denref (a.rep), den);
}
mpq_canonicalize (a.rep);
return a;
}
/** Random field element creator.
* This returns a random field element from the information supplied
* at the creation of the generator.
* Required by abstract base class.
* @param[out] a random field element.
* @return reference to random field element \p a.
*/
ElementAbstract &random (ElementAbstract &a) const
{
Element tmp;
random (tmp);
return (a = ElementEnvelope <GMPRationalField> (tmp));
}
const GMPRationalField& ring() const { return _field; }
private:
GMPRationalField _field; //!< @internal rational field
integer _size; //!< @internal ??
integer _seed; //!< @internal seed
}; // class GMPRationalRandIter
} // namespace LinBox
#endif // __LINBOX_randiter_gmp_random_H
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
|