Header only for random.cpp.

For the header only version, the global variable default_random no more exist => we need to replace all occurences of default_random by a call to the global function get_default_random().
As usual, no modification for the non header only version.
This commit is contained in:
Guillaume Damiand 2014-11-14 14:20:26 +01:00
parent 707aae22b0
commit ebc4300334
40 changed files with 283 additions and 229 deletions

View File

@ -58,7 +58,7 @@ class Min_circle_2 {
Min_circle_2( InputIterator first,
InputIterator last,
bool randomize = false,
Random& random = default_random,
Random& random = get_default_random(),
const Traits& traits = Traits());
Min_circle_2( const Traits& traits = Traits());
@ -302,7 +302,7 @@ class Min_circle_2 {
= false
#endif
,
Random& random = default_random,
Random& random = get_default_random(),
const Traits& traits = Traits())
: tco( traits)
{

View File

@ -57,7 +57,7 @@ class Min_ellipse_2 {
Min_ellipse_2( InputIterator first,
InputIterator last,
bool randomize = false,
Random& random = default_random,
Random& random = get_default_random(),
const Traits& traits = Traits());
Min_ellipse_2( const Traits& traits = Traits());
@ -328,7 +328,7 @@ class Min_ellipse_2 {
= false
#endif
,
Random& random = default_random,
Random& random = get_default_random(),
const Traits& traits = Traits())
: tco( traits)
{

View File

@ -45,7 +45,6 @@ using CGAL::Creator_uniform_2;
using CGAL::Random_points_in_square_2;
using CGAL::Random;
using CGAL::Timer;
using CGAL::default_random;
using CGAL::rectangular_p_center_2;
#ifndef CGAL_PCENTER_NO_OUTPUT
using std::ostream;
@ -108,7 +107,7 @@ public:
Random_p_clusters_2(int n_,
double c_size_,
double r = 1,
Random& rnd = default_random)
Random& rnd = CGAL::get_default_random())
: Base(r - c_size_, rnd),
n(n_),
c_size(c_size_),
@ -163,7 +162,7 @@ main(int argc, char* argv[])
#endif // CGAL_PCENTER_NO_OUTPUT
// generate random seed
random_seed = default_random.get_int(0, (1 << 30));
random_seed = CGAL::get_default_random().get_int(0, (1 << 30));
}
else
random_seed = atoi(argv[2]);

View File

@ -50,7 +50,6 @@ using CGAL::Creator_uniform_2;
using CGAL::Random_points_in_square_2;
using CGAL::Random;
using CGAL::Timer;
using CGAL::default_random;
using CGAL::rectangular_p_center_2;
#ifndef CGAL_PCENTER_NO_OUTPUT
using std::ostream;
@ -110,7 +109,7 @@ public:
Random_p_clusters_2(int n_,
double c_size_,
double r = 1,
Random& rnd = default_random)
Random& rnd = CGAL::get_default_random())
: Base(r - c_size_, rnd),
n(n_),
c_size(c_size_),
@ -165,7 +164,7 @@ main(int argc, char* argv[])
#endif // CGAL_PCENTER_NO_OUTPUT
// generate random seed
random_seed = default_random.get_int(0, (1 << 30));
random_seed = CGAL::get_default_random().get_int(0, (1 << 30));
}
else
random_seed = std::atoi(argv[2]);

View File

@ -73,8 +73,8 @@ void process ()
for ( int i = 0; i < 100; ++i) {
points.push_back
(typename K::Point_2
(CGAL::default_random( 0x100000),
CGAL::default_random( 0x100000),
(CGAL::get_default_random()( 0x100000),
CGAL::get_default_random()( 0x100000),
hom));
}

View File

@ -73,9 +73,9 @@ void process ()
for ( int i = 0; i < 100; ++i) {
points.push_back
(typename K::Point_3
(CGAL::default_random( 0x100000),
CGAL::default_random( 0x100000),
CGAL::default_random( 0x100000),
(CGAL::get_default_random()( 0x100000),
CGAL::get_default_random()( 0x100000),
CGAL::get_default_random()( 0x100000),
hom));
}

View File

@ -75,7 +75,7 @@ void process ()
double hom = 2.0;
for ( i = 0; i < 100; ++i) {
for (j=0; j<d; ++j)
coords[ j] = CGAL::default_random( 0x100000);
coords[ j] = CGAL::get_default_random()( 0x100000);
coords[d] = hom;
points.push_back
(typename K::Point_d(d, coords.begin(), coords.end()));

View File

@ -124,7 +124,7 @@ int main() {
{
// fill the 2x2x2 image
for(int i = 0; i < 8; ++i) {
data[i] = CGAL::default_random.get_int(0,255);
data[i] = CGAL::get_default_random().get_int(0,255);
}
// test the difference between the two implementations

View File

@ -57,7 +57,7 @@ CGAL::Point_d<R> random_point_in_range(int d,int l,int h,
{
std::vector<int> V(d+1); V[d]=1;
for(int i = 0; i<d; ++i)
V[i] = CGAL::default_random.get_int(l,h);
V[i] = CGAL::get_default_random().get_int(l,h);
return CGAL::Point_d<R>(d,V.begin(),V.end());
}

View File

@ -59,7 +59,7 @@ CGAL::Timer timer;
void random_d_tuple_in_range(p_int V, int d, int l, int h)
{
for(int i = 0; i<d; ++i)
V[i] = CGAL::default_random.get_int(l,h);
V[i] = CGAL::get_default_random().get_int(l,h);
}
void random_d_tuples_in_range(pp_int V, int n, int d, int l, int h)

View File

@ -54,7 +54,7 @@ CGAL::Point_d<R> random_point_in_range(int d,int l,int h,
{
std::vector<int> V(d+1); V[d]=1;
for(int i = 0; i<d; ++i)
V[i] = CGAL::default_random.get_int(l,h);
V[i] = CGAL::get_default_random().get_int(l,h);
return CGAL::Point_d<R>(d,V.begin(),V.end());
}

View File

@ -40,7 +40,7 @@ int main() {
// Use a random permutation to hide the creation history
// of the point set.
std::random_shuffle( points.begin(), points.end(), default_random);
std::random_shuffle( points.begin(), points.end(), get_default_random());
// Check range of values.
for ( Vector::iterator i = points.begin(); i != points.end(); i++){

View File

@ -68,7 +68,7 @@ protected:
public:
typedef Random_generator_base<T> This;
Random_generator_base() : _rnd( default_random) {}
Random_generator_base() : _rnd( get_default_random()) {}
Random_generator_base( double range, Random& rnd)
: Generator_base<T>( range), _rnd( rnd) {}
Random_generator_base( const T& item, double range, Random& rnd)
@ -83,7 +83,7 @@ class Random_double_in_interval : public Random_generator_base<double> {
public:
typedef Random_double_in_interval This;
Random_double_in_interval(double a = 1, Random& rnd = default_random)
Random_double_in_interval(double a = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed in the half-open square with side length a,
// centered around the origin, i.e. \forall p = `*g': -\frac{a}{2}

View File

@ -36,7 +36,7 @@ class Random_points_in_disc_2 : public Random_generator_base<P>{
void generate_point();
public:
typedef Random_points_in_disc_2<P,Creator> This;
Random_points_in_disc_2( double r = 1, Random& rnd = default_random)
Random_points_in_disc_2( double r = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed in the open disc with radius r, i.e. |`*g'| < r .
// Two random numbers are needed from `rnd' for each point.
@ -71,7 +71,7 @@ class Random_points_on_circle_2 : public Random_generator_base<P> {
void generate_point();
public:
typedef Random_points_on_circle_2<P,Creator> This;
Random_points_on_circle_2( double r = 1, Random& rnd = default_random)
Random_points_on_circle_2( double r = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed on the circle with radius r, i.e. |`*g'| == r . A
// single random number is needed from `rnd' for each point.
@ -105,7 +105,7 @@ class Random_points_in_square_2 : public Random_generator_base<P> {
void generate_point();
public:
typedef Random_points_in_square_2<P,Creator> This;
Random_points_in_square_2( double a = 1, Random& rnd = default_random)
Random_points_in_square_2( double a = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed in the half-open square with side length a,
// centered around the origin, i.e. \forall p = `*g': -\frac{a}{2}
@ -141,7 +141,7 @@ class Random_points_on_square_2 : public Random_generator_base<P> {
void generate_point();
public:
typedef Random_points_on_square_2<P,Creator> This;
Random_points_on_square_2( double a = 1, Random& rnd = default_random)
Random_points_on_square_2( double a = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed on the boundary of the square with side length a,
// centered around the origin, i.e. \forall p = `*g': one
@ -194,7 +194,7 @@ class Random_points_in_iso_rectangle_2 : public Random_generator_base<P> {
void generate_point();
public:
typedef Random_points_in_iso_rectangle_2<P,Creator> This;
Random_points_in_iso_rectangle_2( const P&p, const P& q, Random& rnd = default_random)
Random_points_in_iso_rectangle_2( const P&p, const P& q, Random& rnd = get_default_random())
: Random_generator_base<P>( 1.0 , rnd)
{
left = (std::min)(to_double(p.x()), to_double(q.x()));
@ -238,7 +238,7 @@ public:
typedef Random_points_on_segment_2<P,Creator> This;
Random_points_on_segment_2( const P& p = P( -1, 0),
const P& q = P( 1, 0),
Random& rnd = default_random)
Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed on the segment from p to q except q, i.e. `*g' ==
// \lambda p + (1-\lambda)\, q where 0 <= \lambda < 1 . A single
@ -423,7 +423,7 @@ void perturb_points_2( ForwardIterator first,
double xeps,
double yeps)
{
perturb_points_2( first, last, xeps, yeps, default_random);
perturb_points_2( first, last, xeps, yeps, get_default_random());
}
template <class ForwardIterator>
@ -431,7 +431,7 @@ void perturb_points_2( ForwardIterator first,
ForwardIterator last,
double xeps)
{
perturb_points_2( first, last, xeps, xeps, default_random);
perturb_points_2( first, last, xeps, xeps, get_default_random());
}
template <class RandomAccessIterator, class OutputIterator, class Creator>
OutputIterator random_collinear_points_2(
@ -489,7 +489,7 @@ OutputIterator random_collinear_points_2(
OutputIterator first2)
{
return random_collinear_points_2( first, last, n, first2,
default_random);
get_default_random());
}

View File

@ -36,7 +36,7 @@ class Random_points_in_sphere_3 : public Random_generator_base<P> {
void generate_point();
public:
typedef Random_points_in_sphere_3<P,Creator> This;
Random_points_in_sphere_3( double r = 1, Random& rnd = default_random)
Random_points_in_sphere_3( double r = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed in the open sphere with radius r, i.e. |`*g'| < r .
// Three random numbers are needed from `rnd' for each point
@ -75,7 +75,7 @@ class Random_points_on_sphere_3 : public Random_generator_base<P> {
void generate_point();
public:
typedef Random_points_on_sphere_3<P,Creator> This;
Random_points_on_sphere_3( double r = 1, Random& rnd = default_random)
Random_points_on_sphere_3( double r = 1, Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed on the sphere with radius r, i.e. |`*g'| == r . A
// two random numbers are needed from `rnd' for each point.
@ -113,7 +113,7 @@ class Random_points_in_cube_3 : public Random_generator_base<P>{
void generate_point();
public:
typedef Random_points_in_cube_3<P,Creator> This;
Random_points_in_cube_3( double a = 1, Random& rnd = default_random)
Random_points_in_cube_3( double a = 1, Random& rnd = get_default_random())
: Random_generator_base<P>( a, rnd) { generate_point(); }
This& operator++() {
generate_point();

View File

@ -35,7 +35,7 @@ class Random_points_in_ball_d : public Random_generator_base<P>{
public:
typedef Random_points_in_ball_d<P> This;
Random_points_in_ball_d( int dim, double a = 1,
Random& rnd = default_random)
Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed in the open sphere with radius r, i.e. |`*g'| < r .
: Random_generator_base<P>( a, rnd), dimension(dim) { generate_point(); }
@ -84,7 +84,7 @@ class Random_points_on_sphere_d : public Random_generator_base<P>{
public:
typedef Random_points_on_sphere_d<P> This;
Random_points_on_sphere_d( int dim, double a = 1,
Random& rnd = default_random)
Random& rnd = get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed on the sphere with radius r, i.e. |`*g'| == r .
: Random_generator_base<P>( a, rnd), dimension(dim) { generate_point(); }
@ -129,7 +129,7 @@ class Random_points_in_cube_d : public Random_generator_base<P>{
public:
typedef Random_points_in_cube_d<P> This;
Random_points_in_cube_d( int dim, double a = 1,
Random& rnd = default_random)
Random& rnd = get_default_random())
: Random_generator_base<P>( a, rnd), dimension(dim) { generate_point(); }
This& operator++() {
generate_point();

View File

@ -57,7 +57,7 @@ OutputIterator random_selection( RandomAccessIterator first,
Size n,
OutputIterator result)
{
return random_selection( first, last, n, result, default_random);
return random_selection( first, last, n, result, get_default_random());
}
} //namespace CGAL

View File

@ -97,7 +97,7 @@ void test_point_generators_2() {
perturb_points_2( i1, i2, 10.0);
// Create a random permutation.
std::random_shuffle( points.begin(), points.end(), default_random);
std::random_shuffle( points.begin(), points.end(), get_default_random());
assert( points.size() == 1000);
for ( std::vector<Point_2>::iterator i = points.begin();

View File

@ -24,7 +24,7 @@ typedef CGAL::Delaunay_triangulation_3<K> Delaunay3d;
int my_rand()
{
return int(CGAL::default_random.get_double()*(1<<31));
return int(CGAL::get_default_random().get_double()*(1<<31));
}
int main()

View File

@ -39,7 +39,7 @@ int main(int argc, char* argv[])
typedef LA::Matrix Matrix;
typedef LA::Vector Vector;
bool IOTEST = true;
{
{
int vec_dim;
if (argc == 2) vec_dim = std::atoi(argv[1]);
else vec_dim = VEC_DIM;
@ -48,7 +48,7 @@ int main(int argc, char* argv[])
Vector v0(vec_dim), v1(vec_dim), v2(vec_dim);
int F[] = { 1,2,3,4,5 };
Vector v11(F,F+2), v12(F,F+3), v13(F,F+4), v14(F,F+5),
v15(v13.begin(),v13.end()),
v15(v13.begin(),v13.end()),
v16(vec_dim,NT(1));
CGAL_TEST(v13==v15){}
CGAL_TEST(v0==v1){}
@ -64,7 +64,7 @@ int main(int argc, char* argv[])
v1 -= v2;
v1 = -v1;
CGAL_TEST((v1*v1 == NT(vec_dim*vec_dim*vec_dim))){}
/* squared length of (v1 + v2) = v1*v1
/* squared length of (v1 + v2) = v1*v1
should be equal to dim*dim*dim */
NT res1 = (v1*v1 - v2*v2);
NT res2 = ((v1-v2)*(v1+v2));
@ -78,7 +78,7 @@ int main(int argc, char* argv[])
if (IOTEST) CGAL_IO_TEST(v1,v2,CGAL::IO::ASCII);
}
{
{
int mat_dim;
if (argc == 2) mat_dim = std::atoi(argv[1]);
else mat_dim = MAT_DIM;
@ -86,16 +86,16 @@ int main(int argc, char* argv[])
/* some construction and access ops */
Matrix::Identity ID;
Matrix A(mat_dim,mat_dim), B(mat_dim),
I(mat_dim,ID), One(mat_dim,mat_dim,NT(2));
I(mat_dim,ID), One(mat_dim,mat_dim,NT(2));
CGAL_TEST(A==B){}
CGAL_TEST(One*I==One){}
std::vector<Vector> F(mat_dim);
int i,j;
int i,j;
for (i = 0; i < mat_dim; i++) {
Vector v(mat_dim);
for (j = 0; j < mat_dim; j++) {
A(i,j) = i;
for (j = 0; j < mat_dim; j++) {
A(i,j) = i;
B(i,j) = j;
v[j] = j;
}
@ -115,7 +115,7 @@ int main(int argc, char* argv[])
(0,1,2,3...)
(0,1,2,3...)
...
C = A = D = E;
C = A = D = E;
*/
Matrix::iterator it;
@ -130,15 +130,15 @@ int main(int argc, char* argv[])
CGAL_TEST(A.row(1)*B.column(1)==NT(mat_dim)){}
/* some basic arithmetic testing */
C = A; C += A;
C -= NT(3)*A;
C = -C;
C = A; C += A;
C -= NT(3)*A;
C = -C;
CGAL_TEST(C==A){}
/* row sum test: */
Vector ones(mat_dim), row_sum_vec(mat_dim);
Vector ones(mat_dim), row_sum_vec(mat_dim);
for (i = 0; i < mat_dim; i++) {
ones[i] = 1;
ones[i] = 1;
row_sum_vec[i] = i*mat_dim;
}
CGAL_TEST(A*ones==row_sum_vec){}
@ -147,16 +147,16 @@ int main(int argc, char* argv[])
/* matrix operations + ,* and |transpose|, |rank| */
CGAL_TEST(C==LA::transpose(C)){}
C = C-B;
CGAL_TEST(C==A){}
CGAL_TEST(C==A){}
C = I+A;
CGAL_TEST(LA::rank(C)==mat_dim){}
/* matrix operations 2* , |determinant| */
C = NT(2) * I;
C = C * NT(2);
Matrix L,U;
Vector c;
std::vector<int> q;
Matrix L,U;
Vector c;
std::vector<int> q;
NT det = LA::determinant(C, L, U, q, c); // det must be 2^{2*mat_dim}
NT pot = 1; for (i=0; i<mat_dim; ++i) pot *= NT(4);
CGAL_TEST(det == pot){}
@ -165,19 +165,19 @@ int main(int argc, char* argv[])
CGAL_TEST(CGAL_NTS sign(det) == LA::sign_of_determinant(C)){}
if (IOTEST) CGAL_IO_TEST(A,C,CGAL::IO::ASCII);
/* a random linear solver task: */
Vector b(mat_dim),x(mat_dim),e;
NT denom;
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim; j++)
C(i,j) = CGAL::default_random.get_int(-mat_dim,mat_dim);
b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim);
Vector b(mat_dim),x(mat_dim),e;
NT denom;
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim; j++)
C(i,j) = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
b[i] = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
}
for (double f = 1.0; f > 0.0; f-=0.1) {
Matrix E = C;
for (i = 0; i< mat_dim; ++i)
for (j = 0; j < mat_dim; ++j)
if ( CGAL::default_random.get_double() > f ) E(i,j)=0;
if ( CGAL::get_default_random().get_double() > f ) E(i,j)=0;
if (LA::linear_solver(E, b, x, denom, A, e)) {
CGAL_TEST(E*x == b*denom){}
@ -212,10 +212,10 @@ int main(int argc, char* argv[])
if (mat_dim > 1) { // ueberbestimmt:
Matrix N(mat_dim,mat_dim-1);
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim-1; j++)
N(i,j) = CGAL::default_random.get_int(-mat_dim,mat_dim);
b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim);
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim-1; j++)
N(i,j) = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
b[i] = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
}
if (LA::linear_solver(N,b,x,denom,e)) {
CGAL_TEST(N*x == b*denom){}
@ -235,7 +235,7 @@ int main(int argc, char* argv[])
typedef LA::Matrix Matrix;
typedef LA::Vector Vector;
bool IOTEST = false;
{
{
int vec_dim;
if (argc == 2) vec_dim = std::atoi(argv[1]);
else vec_dim = VEC_DIM;
@ -245,7 +245,7 @@ int main(int argc, char* argv[])
Vector v0(vec_dim), v1(vec_dim), v2(vec_dim);
int F[] = { 1,2,3,4,5 };
Vector v11(F,F+2), v12(F,F+3), v13(F,F+4), v14(F,F+5),
v15(v13.begin(),v13.end()),
v15(v13.begin(),v13.end()),
v16(vec_dim,NT(1));
CGAL_TEST(v13==v15){}
CGAL_TEST(v0==v1){}
@ -261,7 +261,7 @@ int main(int argc, char* argv[])
v1 -= v2;
v1 = -v1;
CGAL_TEST((v1*v1 == NT(vec_dim*vec_dim*vec_dim))){}
/* squared length of (v1 + v2) = v1*v1
/* squared length of (v1 + v2) = v1*v1
should be equal to dim*dim*dim */
NT res1 = (v1*v1 - v2*v2);
NT res2 = ((v1-v2)*(v1+v2));
@ -276,7 +276,7 @@ int main(int argc, char* argv[])
if (IOTEST) CGAL_IO_TEST(v1,v2,CGAL::IO::ASCII);
}
{
{
int mat_dim;
if (argc == 2) mat_dim = std::atoi(argv[1]);
else mat_dim = MAT_DIM;
@ -284,16 +284,16 @@ int main(int argc, char* argv[])
/* some construction and access ops */
Matrix::Identity ID;
Matrix A(mat_dim,mat_dim), B(mat_dim),
I(mat_dim,ID), One(mat_dim,mat_dim,NT(2));
I(mat_dim,ID), One(mat_dim,mat_dim,NT(2));
CGAL_TEST(A==B){}
CGAL_TEST(One*I==One){}
std::vector<Vector> F(mat_dim);
int i,j;
int i,j;
for (i = 0; i < mat_dim; i++) {
Vector v(mat_dim);
for (j = 0; j < mat_dim; j++) {
A(i,j) = i;
for (j = 0; j < mat_dim; j++) {
A(i,j) = i;
B(i,j) = j;
v[j] = j;
}
@ -313,7 +313,7 @@ int main(int argc, char* argv[])
(0,1,2,3...)
(0,1,2,3...)
...
C = A = D = E;
C = A = D = E;
*/
Matrix::iterator it;
@ -328,15 +328,15 @@ int main(int argc, char* argv[])
CGAL_TEST(A.row(1)*B.column(1)==NT(mat_dim)){}
/* some basic arithmetic testing */
C = A; C += A;
C -= NT(3)*A;
C = -C;
C = A; C += A;
C -= NT(3)*A;
C = -C;
CGAL_TEST(C==A){}
/* row sum test: */
Vector ones(mat_dim), row_sum_vec(mat_dim);
Vector ones(mat_dim), row_sum_vec(mat_dim);
for (i = 0; i < mat_dim; i++) {
ones[i] = 1;
ones[i] = 1;
row_sum_vec[i] = i*mat_dim;
}
CGAL_TEST(A*ones==row_sum_vec){}
@ -345,16 +345,16 @@ int main(int argc, char* argv[])
/* matrix operations + ,* and |transpose|, |rank| */
CGAL_TEST(C==LA::transpose(C)){}
C = C-B;
CGAL_TEST(C==A){}
CGAL_TEST(C==A){}
C = I+A;
CGAL_TEST(LA::rank(C)==mat_dim){}
/* matrix operations 2* , |determinant| */
C = NT(2) * I;
C = C * NT(2);
Matrix L,U;
Vector c;
std::vector<int> q;
Matrix L,U;
Vector c;
std::vector<int> q;
NT det = LA::determinant(C, L, U, q, c); // det must be 2^{2*mat_dim}
NT pot = 1; for (i=0; i<mat_dim; ++i) pot *= NT(4);
CGAL_TEST(det == pot){}
@ -364,19 +364,19 @@ int main(int argc, char* argv[])
if (IOTEST) CGAL_IO_TEST(A,C,CGAL::IO::ASCII);
// add binary test later: if (IOTEST) CGAL_IO_TEST(A,C,CGAL::IO::BINARY);
/* a random linear solver task: */
Vector b(mat_dim),x(mat_dim),e;
NT denom;
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim; j++)
C(i,j) = CGAL::default_random.get_int(-mat_dim,mat_dim);
b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim);
Vector b(mat_dim),x(mat_dim),e;
NT denom;
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim; j++)
C(i,j) = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
b[i] = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
}
for (double f = 1.0; f > 0.0; f-=0.1) {
Matrix E = C;
for (i = 0; i< mat_dim; ++i)
for (j = 0; j < mat_dim; ++j)
if ( CGAL::default_random.get_double() > f ) E(i,j)=0;
if ( CGAL::get_default_random().get_double() > f ) E(i,j)=0;
if (LA::linear_solver(E, b, x, denom, A, e)) {
CGAL_TEST(E*x == b*denom){}
@ -409,10 +409,10 @@ int main(int argc, char* argv[])
if (mat_dim > 1) { // ueberbestimmt:
Matrix N(mat_dim,mat_dim-1);
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim-1; j++)
N(i,j) = CGAL::default_random.get_int(-mat_dim,mat_dim);
b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim);
for (i = 0; i < mat_dim; i++) {
for (j = 0; j < mat_dim-1; j++)
N(i,j) = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
b[i] = CGAL::get_default_random().get_int(-mat_dim,mat_dim);
}
if (LA::linear_solver(N,b,x,denom,e)) {
CGAL_TEST(N*x == b*denom){}

View File

@ -61,7 +61,7 @@ int main(int argc, char** argv)
std::cerr << "Filling f with " << number_of_elements << " random integers...\n";
for(unsigned int n=0; n<number_of_elements; n++)
{
int i=CGAL::default_random.get_int(0,1000);
int i=CGAL::get_default_random().get_int(0,1000);
f.insert(i, i*i);
}

View File

@ -30,7 +30,7 @@ int main(int, char**)
for(int n=0; n<500; n++)
{
int i=CGAL::default_random.get_int(0,1000);
int i=CGAL::get_default_random().get_int(0,1000);
if((i%2)==1) ++real_number_of_odds;
q.add_bad_element(i);
}

View File

@ -19,7 +19,7 @@ typedef CGAL::Quotient<MPF> QMPF;
double non_zero_double(){
double d;
do {
d = CGAL::default_random.get_double();
d = CGAL::get_default_random().get_double();
if(d ==0) {
std::cout << "generated zero" << std::endl;
}
@ -130,7 +130,7 @@ void square_test()
{
for (int i = 0; i<1000; ++i)
{
double d = CGAL::default_random.get_double();
double d = CGAL::get_default_random().get_double();
MPF D(d);
assert(D*D == CGAL_NTS square(D));
}
@ -274,8 +274,8 @@ int main(int argc, char **argv)
std::cout << "Checking MP_Float(float) constructor." << std::endl;
for (int i = 0; i < loops; ++i) {
float d = (float)CGAL::default_random.get_double();
int exp = int((CGAL::default_random.get_double()-.5)*256);
float d = (float)CGAL::get_default_random().get_double();
int exp = int((CGAL::get_default_random().get_double()-.5)*256);
d = std::ldexp(d, exp);
// std::cout << d << std::endl;
// std::cout << MPF(d) << std::endl;
@ -289,8 +289,8 @@ int main(int argc, char **argv)
std::cout << "Checking MP_Float(double) constructor." << std::endl;
MPF y = 0.5000000000000001; // see bug-report on cgal-discuss (2006-06-23).
for (int i = 0; i < loops; ++i) {
double d = CGAL::default_random.get_double();
int exp = int((CGAL::default_random.get_double()-.5)*1024);
double d = CGAL::get_default_random().get_double();
int exp = int((CGAL::get_default_random().get_double()-.5)*1024);
d = std::ldexp(d, exp);
// std::cout << d << std::endl;
// std::cout << MPF(d) << std::endl;
@ -303,9 +303,9 @@ int main(int argc, char **argv)
std::cout << "Checking MP_Float(long double) constructor." << std::endl;
for (int i = 0; i < loops; ++i) {
long double d = CGAL::default_random.get_double();
long double d = CGAL::get_default_random().get_double();
d = d*d; // to get more bits
int exp = int((CGAL::default_random.get_double()-.5)*1024);
int exp = int((CGAL::get_default_random().get_double()-.5)*1024);
d = d * std::ldexp(1.0, exp);
//std::cout << d << std::endl;
//std::cout << MPF(d) << std::endl;

View File

@ -116,7 +116,7 @@ operator<<(std::ostream &os, const Polygon_2<Traits_P,Container_P>& p)
{
typename Polygon_2<Traits_P,Container_P>::Vertex_const_iterator i;
switch(os.iword(IO::mode)) {
switch(get_mode(os)) {
case IO::ASCII :
os << p.size() << ' ';
for (i = p.vertices_begin(); i != p.vertices_end(); ++i) {

View File

@ -285,7 +285,7 @@ Scene_item* cgal_code_remesh(QWidget* parent,
triangulation.dimension() < 3 );
n = triangulation.number_of_vertices())
{
const int pos = CGAL::default_random.get_int(0, (int)polyhedron_points.size());
const int pos = CGAL::get_default_random().get_int(0, (int)polyhedron_points.size());
triangulation.insert(polyhedron_points[pos]);
}
}

View File

@ -55,7 +55,7 @@ typedef CGAL::Polytope_distance_d_traits_2<HK1, RT, double> HTraits1;
#include "test_Polytope_distance_d.h"
template <class K, class Traits>
void process ()
void process ()
{
// generate point set
std::vector<typename K::Point_2> p_points, q_points;
@ -67,26 +67,26 @@ void process ()
for ( i = 0; i < 50; ++i) {
p_points.push_back
(typename K::Point_2(
CGAL::default_random( 0x100000),
CGAL::default_random( 0x100000),
CGAL::get_default_random()( 0x100000),
CGAL::get_default_random()( 0x100000),
hom));
}
hom = 3.0;
for ( i = 0; i < 50; ++i) {
q_points.push_back
(typename K::Point_2(
-CGAL::default_random( 0x100000),
-CGAL::default_random( 0x100000),
-CGAL::get_default_random()( 0x100000),
-CGAL::get_default_random()( 0x100000),
hom));
}
}
// call test function
CGAL::test_Polytope_distance_d( p_points.begin(), p_points.end(),
q_points.begin(), q_points.end(),
Traits(), 1);
}
// main
// ----
int
@ -95,5 +95,5 @@ main()
process<CK1, CTraits1>();
process<HK1, HTraits1>();
}
// ===== EOF ==================================================================

View File

@ -55,7 +55,7 @@ typedef CGAL::Polytope_distance_d_traits_3<HK1, RT, double> HTraits1;
#include "test_Polytope_distance_d.h"
template <class K, class Traits>
void process ()
void process ()
{
// generate point set
std::vector<typename K::Point_3> p_points, q_points;
@ -67,28 +67,28 @@ void process ()
for ( i = 0; i < 50; ++i) {
p_points.push_back
(typename K::Point_3(
CGAL::default_random( 0x100000),
CGAL::default_random( 0x100000),
CGAL::default_random( 0x100000),
CGAL::get_default_random()( 0x100000),
CGAL::get_default_random()( 0x100000),
CGAL::get_default_random()( 0x100000),
hom));
}
hom = 3.0;
for ( i = 0; i < 50; ++i) {
q_points.push_back
(typename K::Point_3(
-CGAL::default_random( 0x100000),
-CGAL::default_random( 0x100000),
-CGAL::default_random( 0x100000),
-CGAL::get_default_random()( 0x100000),
-CGAL::get_default_random()( 0x100000),
-CGAL::get_default_random()( 0x100000),
hom));
}
}
// call test function
CGAL::test_Polytope_distance_d( p_points.begin(), p_points.end(),
q_points.begin(), q_points.end(),
Traits(), 1);
}
// main
// ----
int
@ -97,5 +97,5 @@ main()
process<CK1, CTraits1>();
process<HK1, HTraits1>();
}
// ===== EOF ==================================================================

View File

@ -68,7 +68,7 @@ void process ()
double hom = 2.0;
for ( i = 0; i < 50; ++i) {
for (j=0; j<d; ++j)
coords[ j] = CGAL::default_random( 0x100000);
coords[ j] = CGAL::get_default_random()( 0x100000);
coords[d] = hom;
p_points.push_back
(typename K::Point_d(d, coords.begin(), coords.end()));
@ -76,7 +76,7 @@ void process ()
hom = 3.0;
for ( i = 0; i < 50; ++i) {
for (j=0; j<d; ++j)
coords[ j] = -CGAL::default_random( 0x100000);
coords[ j] = -CGAL::get_default_random()( 0x100000);
coords[d] = hom;
q_points.push_back
(typename K::Point_d(d, coords.begin(), coords.end()));

View File

@ -55,7 +55,7 @@ class QP_partial_exact_pricing : public QP__partial_base<Q,ET,Tags> {
// creation
QP_partial_exact_pricing( bool randomize = false,
Random& random = default_random);
Random& random = get_default_random());
// operations
int pricing(int& direction );

View File

@ -78,7 +78,7 @@ class QP_partial_filtered_pricing
// creation
QP_partial_filtered_pricing( bool randomize = false,
Random& random = default_random,
Random& random = get_default_random(),
ET2NT et2nt = ET2NT());
// operations

View File

@ -222,12 +222,16 @@ public:
boost::rand48 rng;
};
#ifndef CGAL_HEADER_ONLY
// Global variables
// ================
CGAL_EXPORT extern Random default_random;
#endif // CGAL_HEADER_ONLY
} //namespace CGAL
#ifdef CGAL_HEADER_ONLY
#include <CGAL/Random_impl.h>
#endif // CGAL_HEADER_ONLY
#endif // CGAL_RANDOM_H

View File

@ -0,0 +1,105 @@
// Copyright (c) 1997-2001
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel). All rights reserved.
//
// This file is part of CGAL (www.cgal.org); 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 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Sven Schönherr <sven@inf.ethz.ch>
#ifdef CGAL_HEADER_ONLY
#define CGAL_INLINE_FUNCTION inline
#else
#define CGAL_INLINE_FUNCTION
#endif
#include <ctime>
#include <sstream>
namespace CGAL {
#ifdef CGAL_HEADER_ONLY
inline Random& get_default_random()
{
static Random default_random;
return default_random;
}
#else // CGAL_HEADER_ONLY
inline Random& get_default_random()
{ return Random::default_random; }
#endif // CGAL_HEADER_ONLY
// Class implementation (continued)
// ================================
// constructors
CGAL_INLINE_FUNCTION
Random::
Random( )
: val(0)
{
// get system's time
std::time_t s;
std::time( &s);
seed = (unsigned int)s;
// initialize random numbers generator
rng.seed(static_cast<boost::int32_t>(seed));
random_value = get_int(0, 1<<15);
}
CGAL_INLINE_FUNCTION
Random::
Random( unsigned int seed)
: val(0), seed(seed)
{
// initialize random numbers generator
rng.seed(static_cast<boost::int32_t>(seed));
random_value = get_int(0, 1<<15);
}
// seed
CGAL_INLINE_FUNCTION
unsigned int
Random::get_seed () const
{
return seed;
}
// state
CGAL_INLINE_FUNCTION
void
Random::save_state( Random::State& state) const
{
std::ostringstream os;
os << rng;
state = Random::State(os.str(),random_value, val, seed);
}
CGAL_INLINE_FUNCTION
void
Random::restore_state( const Random::State& state)
{
std::istringstream is(state.rng);
is >> rng;
random_value = state.random_value;
val = state.val;
seed = state.seed;
}
} //namespace CGAL

View File

@ -22,67 +22,15 @@
//
// Author(s) : Sven Schönherr <sven@inf.ethz.ch>
#ifndef CGAL_HEADER_ONLY
#include <CGAL/Random.h>
#include <ctime>
#include <sstream>
#include <CGAL/Random_impl.h>
namespace CGAL {
// Class implementation (continued)
// ================================
// constructors
Random::
Random( )
: val(0)
{
// get system's time
std::time_t s;
std::time( &s);
seed = (unsigned int)s;
// initialize random numbers generator
rng.seed(static_cast<boost::int32_t>(seed));
random_value = get_int(0, 1<<15);
}
Random::
Random( unsigned int seed)
: val(0), seed(seed)
{
// initialize random numbers generator
rng.seed(static_cast<boost::int32_t>(seed));
random_value = get_int(0, 1<<15);
}
// seed
unsigned int
Random::get_seed () const
{
return seed;
}
// state
void
Random::save_state( Random::State& state) const
{
std::ostringstream os;
os << rng;
state = Random::State(os.str(),random_value, val, seed);
}
void
Random::restore_state( const Random::State& state)
{
std::istringstream is(state.rng);
is >> rng;
random_value = state.random_value;
val = state.val;
seed = state.seed;
}
// Global variables
// ================
Random default_random;
} //namespace CGAL
#endif

View File

@ -32,33 +32,33 @@ main()
{
// test get_bool
{
bool b = CGAL::default_random.get_bool();
bool b = CGAL::get_default_random().get_bool();
assert( ! b || b);
}
// test get_int
{
int l = CGAL::default_random.get_int( -100, 0);
int u = CGAL::default_random.get_int( 0, 1000);
int i = CGAL::default_random.get_int( l, u);
int l = CGAL::get_default_random().get_int( -100, 0);
int u = CGAL::get_default_random().get_int( 0, 1000);
int i = CGAL::get_default_random().get_int( l, u);
assert( ( l <= i) && ( i < u));
{
std::size_t l = 0, u = 10;
std::size_t i = CGAL::default_random.uniform_int(l,u);
std::size_t i = CGAL::get_default_random().uniform_int(l,u);
assert( ( l <= i) && ( i <= u));
}
{
std::ptrdiff_t l = 0, u = 10;
std::ptrdiff_t i = CGAL::default_random.uniform_int(l,u);
std::ptrdiff_t i = CGAL::get_default_random().uniform_int(l,u);
assert( ( l <= i) && ( i <= u));
}
{
std::ptrdiff_t l = 0, u = 10;
std::ptrdiff_t i = CGAL::default_random.uniform_smallint(l,u);
std::ptrdiff_t i = CGAL::get_default_random().uniform_smallint(l,u);
assert( ( l <= i) && ( i <= u));
}
@ -67,39 +67,39 @@ main()
// test get_double
{
double l = CGAL::default_random.get_double( -123.45, -0.99);
double u = CGAL::default_random.get_double( 22.0/7.0, 33.3);
double d = CGAL::default_random.get_double( l, u);
double l = CGAL::get_default_random().get_double( -123.45, -0.99);
double u = CGAL::get_default_random().get_double( 22.0/7.0, 33.3);
double d = CGAL::get_default_random().get_double( l, u);
assert( ( l <= d) && ( d < u));
double ho = CGAL::default_random.get_double(0.5);
double ho = CGAL::get_default_random().get_double(0.5);
assert( (0.5 <= ho) && (ho < 1.0));
double zo = CGAL::default_random.get_double();
double zo = CGAL::get_default_random().get_double();
assert( (0 <= zo) && (zo < 1.0));
}
// test uniform_real
{
double d = CGAL::default_random.uniform_real<double>(-10.0, 10.0);
double d = CGAL::get_default_random().uniform_real<double>(-10.0, 10.0);
assert( (d >= -10.0) && (d < 10.0) );
d = CGAL::default_random.uniform_real<double>(0.2);
d = CGAL::get_default_random().uniform_real<double>(0.2);
assert( (d >= 0.2) && (d < 1.0) );
d = CGAL::default_random.uniform_real<double>();
d = CGAL::get_default_random().uniform_real<double>();
assert( (d >= 0) && (d < 1) );
d = CGAL::default_random.uniform_01<double>();
d = CGAL::get_default_random().uniform_01<double>();
assert( (d >= 0) && (d < 1) );
}
{
float d = CGAL::default_random.uniform_real<float>(-10.0f, 10.0f);
float d = CGAL::get_default_random().uniform_real<float>(-10.0f, 10.0f);
assert( (d >= -10.0f) && (d < 10.0f) );
d = CGAL::default_random.uniform_real<float>(0.2f);
d = CGAL::get_default_random().uniform_real<float>(0.2f);
assert( (d >= 0.2) && (d < 1.0) );
d = CGAL::default_random.uniform_real<float>();
d = CGAL::get_default_random().uniform_real<float>();
assert( (d >= 0) && (d < 1) );
d = CGAL::default_random.uniform_01<float>();
d = CGAL::get_default_random().uniform_01<float>();
assert( (d >= 0) && (d < 1) );
}
@ -110,10 +110,10 @@ main()
int p3[8] = {0,};
int p4[16] = {0,};
for (int loops=0; loops < (1<<16); ++loops) {
unsigned int l1 = CGAL::default_random.get_bits<1>();
unsigned int l2 = CGAL::default_random.get_bits<2>();
unsigned int l3 = CGAL::default_random.get_bits<3>();
unsigned int l4 = CGAL::default_random.get_bits<4>();
unsigned int l1 = CGAL::get_default_random().get_bits<1>();
unsigned int l2 = CGAL::get_default_random().get_bits<2>();
unsigned int l3 = CGAL::get_default_random().get_bits<3>();
unsigned int l4 = CGAL::get_default_random().get_bits<4>();
assert(l1 < 2);
assert(l2 < 4);
assert(l3 < 8);
@ -138,7 +138,7 @@ main()
// test operator()
{
int i = CGAL::default_random( 5555);
int i = CGAL::get_default_random()( 5555);
assert( ( 0 <= i) && ( i < 5555));
}
@ -160,7 +160,7 @@ main()
std::vector<int> numbers;
numbers.push_back(1);
std::random_shuffle(numbers.begin(), numbers.end(), CGAL::default_random);
std::random_shuffle(numbers.begin(), numbers.end(), CGAL::get_default_random());
return( 0);
}

View File

@ -63,7 +63,7 @@ class Node_2
public:
Node_2()
: p(NULL), rnd(CGAL::default_random.get_int(0, 100)) {}
: p(NULL), rnd(CGAL::get_default_random().get_int(0, 100)) {}
bool operator==(const Node_2 &n) const { return rnd == n.rnd; }
bool operator!=(const Node_2 &n) const { return rnd != n.rnd; }

View File

@ -47,7 +47,7 @@ public:
int rnd;
Node_2()
: p(NULL), rnd(CGAL::default_random.get_int(0, 100)) {}
: p(NULL), rnd(CGAL::get_default_random().get_int(0, 100)) {}
bool operator==(const Node_2 &n) const { return rnd == n.rnd; }
bool operator!=(const Node_2 &n) const { return rnd != n.rnd; }

View File

@ -153,7 +153,7 @@ public:
~Time_accumulator() { timer.stop(); accumulator += timer.time(); }
};
#define drand48 CGAL::default_random.get_double
#define drand48 CGAL::get_default_random().get_double
Point rnd_point()
{

View File

@ -27,9 +27,9 @@ int main()
// performing nearest vertex queries to a series of random points,
// which is a case where the Fast_location policy is beneficial.
for (int i=0; i<10000; ++i)
T.nearest_vertex(Point(CGAL::default_random.get_double(0, 20),
CGAL::default_random.get_double(0, 20),
CGAL::default_random.get_double(0, 20)));
T.nearest_vertex(Point(CGAL::get_default_random().get_double(0, 20),
CGAL::get_default_random().get_double(0, 20),
CGAL::get_default_random().get_double(0, 20)));
return 0;
}

View File

@ -218,7 +218,7 @@ int main(int argc, char **argv)
int loops = (argc < 2) ? 2000 : std::atoi(argv[1]);
int seed = (argc < 3) ? CGAL::default_random.get_int(0, 1<<30)
int seed = (argc < 3) ? CGAL::get_default_random().get_int(0, 1<<30)
: std::atoi(argv[2]);
std::cout << "Initializing random generator with seed = " << seed

View File

@ -7,8 +7,6 @@ Clement:
#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp"
#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp"
#include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // static mais doit pouvoir se remplacer en membre
#include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp"
#include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp"
@ -22,6 +20,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithm
DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const (ok car utilisé que pour debug)
DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // variable statique de classe
DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // variable statique de classe
DONE #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // variable globale; utilisée directement (donc pb pour header only) -> we need to replace the use of CGAL::default_random by CGAL::get_default_random().
DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp"
DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp"