Index: src/LinearAlgebra/RealSpaceMatrix.cpp
===================================================================
--- src/LinearAlgebra/RealSpaceMatrix.cpp	(revision 63839fc79e8c290c3140390c805105bc4563c078)
+++ src/LinearAlgebra/RealSpaceMatrix.cpp	(revision a5028f9fe5de8314faeb80f8192d465807b8d3f0)
@@ -28,4 +28,6 @@
 #include "LinearAlgebra/Vector.hpp"
 #include "LinearAlgebra/VectorContent.hpp"
+#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
+#include "RandomNumbers/RandomNumberGenerator.hpp"
 
 #include <gsl/gsl_blas.h>
@@ -125,7 +127,12 @@
 {
   double phi[NDIM];
+  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
+  const double rng_min = random.min();
+  const double rng_max = random.max();
+
 
   for (int i=0;i<NDIM;i++) {
-    phi[i] = rand()/(RAND_MAX/(2.*M_PI));
+    phi[i] = (random()/(rng_max-rng_min))*(2.*M_PI);
+    std::cout << "Random angle is " << phi[i] << std::endl;
   }
 
Index: src/SubspaceFactorizer.cpp
===================================================================
--- src/SubspaceFactorizer.cpp	(revision 63839fc79e8c290c3140390c805105bc4563c078)
+++ src/SubspaceFactorizer.cpp	(revision a5028f9fe5de8314faeb80f8192d465807b8d3f0)
@@ -36,4 +36,7 @@
 #include "LinearAlgebra/Subspace.hpp"
 #include "LinearAlgebra/VectorContent.hpp"
+
+#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
+#include "RandomNumbers/RandomNumberGenerator.hpp"
 
 typedef std::set<std::set<size_t> > SetofIndexSets;
@@ -203,9 +206,12 @@
   }
 
+//  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
+//  const double rng_min = rng->min();
+//  const double rng_max = rng->max();
   MatrixContent *matrix = new MatrixContent(matrixdimension,matrixdimension);
   matrix->setZero();
   for (size_t i=0; i<matrixdimension ; i++) {
     for (size_t j=0; j<= i; ++j) {
-      //const double value = 10. * rand() / (double)RAND_MAX;
+      //const double value = 10. * random() / (rng_max-rng_min);
       //const double value = i==j ? 2. : 1.;
       if (i==j)
Index: src/Thermostats/Langevin.cpp
===================================================================
--- src/Thermostats/Langevin.cpp	(revision 63839fc79e8c290c3140390c805105bc4563c078)
+++ src/Thermostats/Langevin.cpp	(revision a5028f9fe5de8314faeb80f8192d465807b8d3f0)
@@ -19,4 +19,7 @@
 #include "CodePatterns/Log.hpp"
 #include "ThermoStatContainer.hpp"
+
+#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
+#include "RandomNumbers/RandomNumberGenerator.hpp"
 
 Langevin::Langevin(double _TempFrequency,double _alpha) :
@@ -73,4 +76,7 @@
 double Langevin::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
   DoLog(2) && (Log() << Verbose(2) <<  "Applying Langevin thermostat..." << endl);
+  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
+  const double rng_min = random.min();
+  const double rng_max = random.max();
   double ekin=0;
   for(ForwardIterator iter=begin;iter!=end;++iter){
@@ -79,5 +85,5 @@
     if ((*iter)->FixedIon == 0) { // even FixedIon moves, only not by other's forces
       // throw a dice to determine whether it gets hit by a heat bath particle
-      if (((((rand()/(double)RAND_MAX))*TempFrequency) < 1.)) {
+      if (((((random()/(rng_max-rng_min)))*TempFrequency) < 1.)) {
         DoLog(3) && (Log() << Verbose(3) << "Particle " << (**iter) << " was hit (sigma " << sigma << "): " << U.Norm() << " -> ");
         // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis
Index: src/boundary.cpp
===================================================================
--- src/boundary.cpp	(revision 63839fc79e8c290c3140390c805105bc4563c078)
+++ src/boundary.cpp	(revision a5028f9fe5de8314faeb80f8192d465807b8d3f0)
@@ -40,4 +40,6 @@
 #include "LinearAlgebra/Plane.hpp"
 #include "LinearAlgebra/RealSpaceMatrix.hpp"
+#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
+#include "RandomNumbers/RandomNumberGenerator.hpp"
 #include "Box.hpp"
 
@@ -831,5 +833,8 @@
 
   // initialize seed of random number generator to current time
-  srand ( time(NULL) );
+  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
+  const double rng_min = random.min();
+  const double rng_max = random.max();
+  //srand ( time(NULL) );
 
   // go over [0,1]^3 filler grid
@@ -841,5 +846,5 @@
         // create molecule random translation vector ...
         for (int i=0;i<NDIM;i++)
-          FillerTranslations[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);
+          FillerTranslations[i] = RandomMolDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
         DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl);
 
@@ -851,5 +856,5 @@
         if (DoRandomRotation)
           for (int i=0;i<NDIM;i++)
-            phi[i] = (rand()/RAND_MAX)*(2.*M_PI);
+            phi[i] = (random()/(rng_max-rng_min))*(2.*M_PI);
 
         for(molecule::const_iterator iter = filler->begin(); iter !=filler->end();++iter){
@@ -857,5 +862,5 @@
           // create atomic random translation vector ...
           for (int i=0;i<NDIM;i++)
-            AtomTranslations[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);
+            AtomTranslations[i] = RandomAtomDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
 
           // ... and rotation matrix
@@ -939,7 +944,11 @@
     molecule *&Filling,
     double RandomAtomDisplacement,
-    RealSpaceMatrix &Rotations
+    RealSpaceMatrix &Rotations,
+    RandomNumberGenerator &random
     )
 {
+  const double rng_min = random.min();
+  const double rng_max = random.max();
+
   Vector AtomTranslations;
   for(molecule::iterator miter = Filling->begin(); miter != Filling->end(); ++miter) {
@@ -949,5 +958,5 @@
     // create atomic random translation vector ...
     for (int i=0;i<NDIM;i++)
-      AtomTranslations[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);
+      AtomTranslations[i] = RandomAtomDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
     (*miter)->setPosition((*miter)->getPosition() + AtomTranslations);
   }
@@ -1090,5 +1099,8 @@
 
   // initialize seed of random number generator to current time
-  srand ( time(NULL) );
+  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
+  const double rng_min = random.min();
+  const double rng_max = random.max();
+  //srand ( time(NULL) );
 
   // go over [0,1]^3 filler grid
@@ -1099,6 +1111,6 @@
         CurrentPosition = M * Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
         // create molecule random translation vector ...
-        for (int i=0;i<NDIM;i++)
-          FillerTranslations[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);
+        for (int i=0;i<NDIM;i++) // have the random values [-1,1]*RandomMolDisplacement
+          FillerTranslations[i] = RandomMolDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
         DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl);
 
@@ -1130,5 +1142,5 @@
           // fill!
           Filling = filler->CopyMolecule();
-          RandomizeMoleculePositions(Filling, RandomAtomDisplacement, Rotations);
+          RandomizeMoleculePositions(Filling, RandomAtomDisplacement, Rotations, random);
           // translation
           Filling->Translate(&Inserter);
@@ -1168,5 +1180,5 @@
     else
       Rotations.setIdentity();
-    RandomizeMoleculePositions(filler, RandomAtomDisplacement, Rotations);
+    RandomizeMoleculePositions(filler, RandomAtomDisplacement, Rotations, random);
     // translation
     filler->Translate(&firstInserter);
Index: src/ellipsoid.cpp
===================================================================
--- src/ellipsoid.cpp	(revision 63839fc79e8c290c3140390c805105bc4563c078)
+++ src/ellipsoid.cpp	(revision a5028f9fe5de8314faeb80f8192d465807b8d3f0)
@@ -36,4 +36,7 @@
 #include "LinearAlgebra/RealSpaceMatrix.hpp"
 #include "CodePatterns/Verbose.hpp"
+
+#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
+#include "RandomNumbers/RandomNumberGenerator.hpp"
 
 /** Determines squared distance for a given point \a x to surface of ellipsoid.
@@ -258,7 +261,25 @@
   }
 
+  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator("mt19937", "uniform_int");
+  // check that random number generator's bounds are ok
+  ASSERT(random.min() == 0,
+      "PickRandomNeighbouredPointSet: Chosen RandomNumberGenerator's min "
+      +toString(random.min())+" is not 0!");
+  ASSERT(random.max() >= LC->N[0],
+      "PickRandomNeighbouredPointSet: Chosen RandomNumberGenerator's max "
+      +toString(random.max())+" is too small"+toString(LC->N[0])
+      +" for axis 0!");
+  ASSERT(random.max() >= LC->N[1],
+      "PickRandomNeighbouredPointSet: Chosen RandomNumberGenerator's max "
+      +toString(random.max())+" is too small"+toString(LC->N[1])
+      +" for axis 1!");
+  ASSERT(random.max() >= LC->N[2],
+      "PickRandomNeighbouredPointSet: Chosen RandomNumberGenerator's max "
+      +toString(random.max())+" is too small"+toString(LC->N[2])
+      +" for axis 2!");
+
   do {
     for(int i=0;i<NDIM;i++) // pick three random indices
-      LC->n[i] = (rand() % LC->N[i]);
+      LC->n[i] = ((int)random() % LC->N[i]);
     DoLog(2) && (Log() << Verbose(2) << "INFO: Center cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " ... ");
     // get random cell
@@ -293,5 +314,5 @@
     PickedAtomNrs.clear();
     do {
-      index = (rand() % PointsLeft);
+      index = (((int)random()) % PointsLeft);
       current = PickedAtomNrs.find(index);  // not present?
       if (current == PickedAtomNrs.end()) {
@@ -358,8 +379,11 @@
   }
 
+  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator("mt19937", "uniform_int");
+  const double rng_min = random.min();
+  const double rng_max = random.max();
   if (List != NULL)
     for (PointMap::iterator Runner = List->begin(); Runner != List->end(); Runner++) {
       threshold = 1. - (double)(PointsToPick - PointsPicked)/(double)PointsLeft;
-      value = (double)rand()/(double)RAND_MAX;
+      value = (double)random()/(double)(rng_max-rng_min);
       //Log() << Verbose(3) << "Current node is " << *Runner->second->node << " with " << value << " ... " << threshold << ": ";
       if (value > threshold) {
Index: src/unittests/SubspaceFactorizerUnitTest.cpp
===================================================================
--- src/unittests/SubspaceFactorizerUnitTest.cpp	(revision 63839fc79e8c290c3140390c805105bc4563c078)
+++ src/unittests/SubspaceFactorizerUnitTest.cpp	(revision a5028f9fe5de8314faeb80f8192d465807b8d3f0)
@@ -39,4 +39,7 @@
 #include "LinearAlgebra/VectorContent.hpp"
 
+#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
+#include "RandomNumbers/RandomNumberGenerator.hpp"
+
 #include "SubspaceFactorizerUnitTest.hpp"
 
@@ -49,9 +52,12 @@
 
 void SubspaceFactorizerUnittest::setUp(){
+//  RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
+//  const double rng_min = rng->min();
+//  const double rng_max = rng->max();
   matrix = new MatrixContent(matrixdimension,matrixdimension);
   matrix->setZero();
   for (size_t i=0; i<matrixdimension ; i++) {
     for (size_t j=0; j<= i; ++j) {
-      //const double value = 10. * rand() / (double)RAND_MAX;
+      //const double value = 10. * random() / (rng_max-rng_min);
       //const double value = i==j ? 2. : 1.;
       if (i==j)
