diff --git a/misc/test/src/C++/faust_matdense_conjugate.cpp.in b/misc/test/src/C++/faust_matdense_conjugate.cpp.in
index b252365514526299f3070f282b57a0adebb1afee..10e4e74542d1d686da40925c1417f1683f75cda8 100644
--- a/misc/test/src/C++/faust_matdense_conjugate.cpp.in
+++ b/misc/test/src/C++/faust_matdense_conjugate.cpp.in
@@ -15,29 +15,29 @@ int main(int argc, char* argv[])
 	faust_unsigned_int dim1 = 3;
 	faust_unsigned_int dim2 = 4;
 
-	MatDense<FPP,Cpu>* M;
+	MatDense<FPP,Cpu> M(dim1, dim2);
 	MatDense<FPP,Cpu> M_copy;
-	M = MatDense<FPP,Cpu>::randMat(dim1,dim2);
-	M_copy = *M;
+	M.setRand();
+	M_copy = M;
 	cout<<"mat value"<<endl;
-	M->Display();
+	M.Display();
 
-	M->conjugate(false);
+	M.conjugate(false);
 	cout<<"conjugate mat value (without eval)"<<endl;
-	M->Display();
+	M.Display();
 
-	M->transpose();
+	M.transpose();
 	cout<<"conjugate-transpose mat value (with eval)"<<endl;
-	M->Display();
+	M.Display();
 
-	M->conjugate();
+	M.conjugate();
 	cout << "transpose mat value from conjugate-transpose (with eval)" << endl;
-	M->Display();
+	M.Display();
 
-	M->transpose();
-	assert(M->isEqual(M_copy));
+	M.transpose();
+	assert(M.isEqual(M_copy));
 	cout << "mat value:" << endl;
-	M->Display();
+	M.Display();
 
 	return 0;
 }
diff --git a/src/faust_linear_operator/CPU/faust_MatDense.h b/src/faust_linear_operator/CPU/faust_MatDense.h
index 26cb1712923ee87df9b5fbd449ea4393847b6130..7b66fb23bfd97a214c69222936454ed21dabff3c 100644
--- a/src/faust_linear_operator/CPU/faust_MatDense.h
+++ b/src/faust_linear_operator/CPU/faust_MatDense.h
@@ -264,6 +264,10 @@ namespace Faust
 			// \brief Sets all nonzeros to one.
 			void setNZtoOne();
 
+			// \brief Sets the matrix to random values.
+			// \note using this function is preferable instead of using randMat functions.
+			void setRand();
+
 			//! \brief Returns the identity matrix.
 			static MatDense<FPP,Cpu> eye(faust_unsigned_int nrows, faust_unsigned_int ncols);
 
diff --git a/src/faust_linear_operator/CPU/faust_MatDense.hpp b/src/faust_linear_operator/CPU/faust_MatDense.hpp
index e86b87dea561882f1292e520427c933bfdbe197a..81e294d06dce2fb357ee90516e9cd6d710c69942 100644
--- a/src/faust_linear_operator/CPU/faust_MatDense.hpp
+++ b/src/faust_linear_operator/CPU/faust_MatDense.hpp
@@ -261,6 +261,15 @@ namespace Faust
 			isZeros = false;
 		}
 
+
+	template<typename FPP>
+		void MatDense<FPP,Cpu>::setRand()
+		{
+			mat = EigDenseMat::Random(mat.rows(), mat.cols());
+			isZeros = false;
+			this->is_identity = false;
+		}
+
 	template<typename FPP>
 		void MatDense<FPP, Cpu>::setNZtoOne()
 		{