diff --git a/dev/initdata/generate-invoice.php b/dev/initdata/generate-invoice.php
index 11d827e0dcf22e59fdb50c82d3de993861df5b00..e7c274040de3928288d42cd248f59402bd886f12 100755
--- a/dev/initdata/generate-invoice.php
+++ b/dev/initdata/generate-invoice.php
@@ -90,7 +90,7 @@ $result=0;
 while ($i < GEN_NUMBER_FACTURE && $result >= 0)
 {
 	$i++;
-	$socid = rand(1, $num_socs);
+	$socid = mt_rand(1, $num_socs);
 
 	print "Invoice ".$i." for socid ".$socid;
 
@@ -105,14 +105,14 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
 		$result=$facture->validate($user);
 		if ($result)
 		{
-			$nbp = rand(2, 5);
+			$nbp = mt_rand(2, 5);
 			$xnbp = 0;
 			while ($xnbp < $nbp)
 			{
-				$prodid = rand(1, $num_prods);
+				$prodid = mt_rand(1, $num_prods);
 				$product=new Product($db);
 				$result=$product->fetch($prodids[$prodid]);
-				$result=$facture->addline($product->description, $product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
+				$result=$facture->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
 			    if ($result < 0)
                 {
                     dol_print_error($db,$propal->error);
diff --git a/dev/initdata/generate-order.php b/dev/initdata/generate-order.php
index 082d5428c97c51cbfa5ae7116826c6f36ea7bb4a..9e96bbd781bdac2a55387180657ee2a1c6374f03 100755
--- a/dev/initdata/generate-order.php
+++ b/dev/initdata/generate-order.php
@@ -165,7 +165,7 @@ for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
     $com = new Commande($db);
 
     $com->socid         = 4;
-    $com->date_commande  = $dates[rand(1, count($dates)-1)];
+    $com->date_commande  = $dates[mt_rand(1, count($dates)-1)];
     $com->note           = 'A comment';
     $com->source         = 1;
     $com->fk_project     = 0;
@@ -179,14 +179,14 @@ for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
 		$result=$com->valid($user);
 		if ($result > 0)
 		{
-            $nbp = rand(2, 5);
+            $nbp = mt_rand(2, 5);
             $xnbp = 0;
             while ($xnbp < $nbp)
             {
-                $prodid = rand(1, $num_prods);
+                $prodid = mt_rand(1, $num_prods);
                 $product=new Product($db);
                 $result=$product->fetch($prodids[$prodid]);
-                $result=$com->addline($product->description, $product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0, 0, 0,  $product->price_base_type, $product->price_ttc, '', '', $product->type);
+                $result=$com->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, 0, 0,  $product->price_base_type, $product->price_ttc, '', '', $product->type);
                 if ($result < 0)
                 {
                     dol_print_error($db,$propal->error);
diff --git a/dev/initdata/generate-product.php b/dev/initdata/generate-product.php
index 975fc1ba33d7951d7ecade50bd8a7553a273c940..fbdde96f95a3604349c5a5354aa2ee54de88abc9 100755
--- a/dev/initdata/generate-product.php
+++ b/dev/initdata/generate-product.php
@@ -85,12 +85,12 @@ for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
 {
     print "Product ".$s;
     $produit = new Product($db);
-    $produit->type = rand(0,1);
+    $produit->type = mt_rand(0,1);
     $produit->status = 1;
     $produit->ref = ($produit->type?'S':'P').time().$s;
     $produit->label = 'Label '.time().$s;
     $produit->description = 'Description '.time().$s;
-    $produit->price = rand(1,1000);
+    $produit->price = mt_rand(1,1000);
     $produit->tva_tx = "19.6";
     $ret=$produit->create($user);
     if ($ret < 0) print "Error $ret - ".$produit->error."\n";
diff --git a/dev/initdata/generate-proposal.php b/dev/initdata/generate-proposal.php
index 8d413a518c1b974e370c3d0dc4553b17e9e7dc8d..071efc0298f854877344f0e28fe1ef6290e0810e 100755
--- a/dev/initdata/generate-proposal.php
+++ b/dev/initdata/generate-proposal.php
@@ -117,7 +117,7 @@ $result=0;
 while ($i < GEN_NUMBER_PROPAL && $result >= 0)
 {
 	$i++;
-	$socid = rand(1, $num_socs);
+	$socid = mt_rand(1, $num_socs);
 	print "Proposal ".$i." for socid ".$socid;
 
 	$soc = new Societe($db);
@@ -140,14 +140,14 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
 	$result=$propal->create($user);
 	if ($result >= 0)
 	{
-		$nbp = rand(2, 5);
+		$nbp = mt_rand(2, 5);
 		$xnbp = 0;
 		while ($xnbp < $nbp)
 		{
-			$prodid = rand(1, $num_prods);
+			$prodid = mt_rand(1, $num_prods);
 			$product=new Product($db);
 			$result=$product->fetch($prodids[$prodid]);
-			$result=$propal->addline($product->description, $product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
+			$result=$propal->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
 			if ($result < 0)
 			{
 				dol_print_error($db,$propal->error);
diff --git a/dev/initdata/generate-thirdparty.php b/dev/initdata/generate-thirdparty.php
index d6e9d4c9393ff3b5c7661194c67ee4b5fa37d8fb..8c3a6e3e86e4a3173b96c21143838bb1b411d7be 100755
--- a/dev/initdata/generate-thirdparty.php
+++ b/dev/initdata/generate-thirdparty.php
@@ -90,30 +90,30 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
     print "Company $s\n";
     $soc = new Societe($db);
     $soc->name = "Company num ".time()."$s";
-    $soc->town = $listoftown[rand(0, count($listoftown)-1)];
-    $soc->client = rand(1,2);		// Une societe sur 2 est prospect, l'autre client
-    $soc->fournisseur = rand(0,1);	// Une societe sur 2 est fournisseur
+    $soc->town = $listoftown[mt_rand(0, count($listoftown)-1)];
+    $soc->client = mt_rand(1,2);		// Une societe sur 2 est prospect, l'autre client
+    $soc->fournisseur = mt_rand(0,1);	// Une societe sur 2 est fournisseur
     $soc->code_client='CU'.time()."$s";
     $soc->code_fournisseur='SU'.time()."$s";
     $soc->tva_assuj=1;
     $soc->country_id=1;
     $soc->country_code='FR';
 	// Un client sur 3 a une remise de 5%
-    $user_remise=rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
+    $user_remise=mt_rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
 	print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
     $soc->note_private = 'Company created by the script generate-societe.php';
     $socid = $soc->create();
 
     if ($socid >= 0)
     {
-        $rand = rand(1,4);
+        $rand = mt_rand(1,4);
         print "> Generates $rand contact(s)\n";
         for ($c = 0 ; $c < $rand ; $c++)
         {
             $contact = new Contact($db);
             $contact->socid = $soc->id;
             $contact->lastname = "Lastname".$c;
-            $contact->firstname = $listoflastname[rand(0, count($listoflastname)-1)];
+            $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)];
             if ( $contact->create($user) )
             {
 
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 3bd52d98e5ffcb0db401b319caa977cadc718bea..4242a23823cc02747ad72eff42abf1c8288904b7 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -2675,7 +2675,7 @@ class Propal extends CommonObject
                 $line->remise_percent=00;
             }
 
-            $prodid = rand(1, $num_prods);
+            $prodid = mt_rand(1, $num_prods);
             $line->fk_product=$prodids[$prodid];
 
             $this->lines[$xnbp]=$line;
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 8f8edcf15a355d23d36ba57d1f6b98b902094117..ed1947ec3ca4c4ae817eec02ed1d833d02ce9e75 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -3224,7 +3224,7 @@ class Commande extends CommonOrder
                 $line->total_tva=19.6;
                 $line->remise_percent=0;
             }
-            $prodid = rand(1, $num_prods);
+            $prodid = mt_rand(1, $num_prods);
             $line->fk_product=$prodids[$prodid];
 
             $this->lines[$xnbp]=$line;
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 953561496228a1206c67f0e9f9a1f9b8d744f107..09b253e08a08dabc5ce39790ea0fb874ab7b7f36 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -3566,7 +3566,7 @@ class Facture extends CommonInvoice
 				$line->remise_percent=0;
 				if ($xnbp == 1)        // Qty is negative (product line)
 				{
-					$prodid = rand(1, $num_prods);
+					$prodid = mt_rand(1, $num_prods);
 					$line->fk_product=$prodids[$prodid];
 					$line->qty=-1;
 					$line->total_ht=-100;
@@ -3583,7 +3583,7 @@ class Facture extends CommonInvoice
 				}
 				else if ($xnbp == 3)    // Discount is 50% (product line)
 				{
-					$prodid = rand(1, $num_prods);
+					$prodid = mt_rand(1, $num_prods);
 					$line->fk_product=$prodids[$prodid];
 					$line->total_ht=50;
 					$line->total_ttc=59.8;
@@ -3592,7 +3592,7 @@ class Facture extends CommonInvoice
 				}
 				else    // (product line)
 				{
-					$prodid = rand(1, $num_prods);
+					$prodid = mt_rand(1, $num_prods);
 					$line->fk_product=$prodids[$prodid];
 					$line->total_ht=100;
 					$line->total_ttc=119.6;
@@ -3621,7 +3621,7 @@ class Facture extends CommonInvoice
 			$line->total_ht=0;
 			$line->total_ttc=0;    // 90 * 1.196
 			$line->total_tva=0;
-			$prodid = rand(1, $num_prods);
+			$prodid = mt_rand(1, $num_prods);
 			$line->fk_product=$prodids[$prodid];
 
 			$this->lines[$xnbp]=$line;
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index 9e8b1de5d07acf3b3ffb50c32f1d1a07a9589100..395e484075df51f8ace654255963f7ce9bcc84b6 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -2147,7 +2147,7 @@ class Contrat extends CommonObject
 			$line->total_ht=90;
 			$line->total_ttc=107.64;	// 90 * 1.196
 			$line->total_tva=17.64;
-			$prodid = rand(1, $num_prods);
+			$prodid = mt_rand(1, $num_prods);
 			$line->fk_product=$prodids[$prodid];
 			$this->lines[$xnbp]=$line;
 			$xnbp++;
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 493afb9e4cced5380d28eecaf13b15918b0ad90c..ebe5509078d9f0c3ebc5f7b47ab3786ad68db3eb 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -5393,7 +5393,7 @@ function dol_set_focus($selector)
 function dol_getmypid()
 {
     if (! function_exists('getmypid')) {
-        return rand(1,32768);
+        return mt_rand(1,32768);
     } else {
         return getmypid();
     }
diff --git a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php
index 7440a357ea8f669330120a2d48e691552140c1a6..af08ae533922f0db5cf5272246fc549fdedcd727 100644
--- a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php
+++ b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php
@@ -134,19 +134,19 @@ class modGeneratePassPerso extends ModeleGenPassword
 	{
 		$pass = "";
 		for($i=0; $i<$this->NbMaj; $i++){ // Y
-			$pass .= $this->Maj[rand(0,strlen($this->Maj) - 1)];
+			$pass .= $this->Maj[mt_rand(0,strlen($this->Maj) - 1)];
 		}
 
 		for($i=0; $i<$this->NbNum; $i++){ // X
-			$pass .= $this->Nb[rand(0,strlen($this->Nb) - 1)];
+			$pass .= $this->Nb[mt_rand(0,strlen($this->Nb) - 1)];
 		}
 
 		for($i=0; $i<$this->NbSpe; $i++){ // @
-			$pass .= $this->Spe[rand(0,strlen($this->Spe) - 1)];
+			$pass .= $this->Spe[mt_rand(0,strlen($this->Spe) - 1)];
 		}
 
 		for($i=strlen($pass);$i<$this->length2; $i++){ // y
-			$pass .= $this->All[rand(0,strlen($this->All) -1)];
+			$pass .= $this->All[mt_rand(0,strlen($this->All) -1)];
 		}
 
 		$pass = str_shuffle($pass);
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index a6bfef7427be5db4278ce423b417fd1296421e8f..95870df027e119e5411adeaa049fdf7e3de0df30 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -1692,7 +1692,7 @@ class FactureFournisseur extends CommonInvoice
     			$line->remise_percent=0;
 			}
 
-			$prodid = rand(1, $num_prods);
+			$prodid = mt_rand(1, $num_prods);
             $line->fk_product=$prodids[$prodid];
             $line->product_type=0;
 
diff --git a/htdocs/opensurvey/fonctions.php b/htdocs/opensurvey/fonctions.php
index 5b11a821b7c1680965defd70683afbbebc5ff571..214fc9130dbe05a22782f712720553248ac1f547 100644
--- a/htdocs/opensurvey/fonctions.php
+++ b/htdocs/opensurvey/fonctions.php
@@ -192,7 +192,7 @@ function dol_survey_random($car)
 	$chaine = "abcdefghijklmnopqrstuvwxyz123456789";
 	srand((double) microtime()*1000000);
 	for($i=0; $i<$car; $i++) {
-		$string .= $chaine[rand()%strlen($chaine)];
+		$string .= $chaine[mt_rand() % strlen($chaine)];
 	}
 	return $string;
 }
diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php
index b9a0e8ab55a4f8e05f112180cf11e4547e2d4804..90a4d70130d7b8a933e7f5a7173d3bf95e380149 100644
--- a/htdocs/projet/class/project.class.php
+++ b/htdocs/projet/class/project.class.php
@@ -955,7 +955,7 @@ class Project extends CommonObject
         $this->budget_amount = 10000;
 
         /*
-        $nbp = rand(1, 9);
+        $nbp = mt_rand(1, 9);
         $xnbp = 0;
         while ($xnbp < $nbp)
         {
diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php
index a6bf22a4b21924805c76ae28c8cd1e3782e6b901..df634da27ae04141afe67e8d038f3506342e9cfa 100644
--- a/htdocs/supplier_proposal/class/supplier_proposal.class.php
+++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php
@@ -2244,7 +2244,7 @@ class SupplierProposal extends CommonObject
                 $line->remise_percent=00;
             }
 
-            $prodid = rand(1, $num_prods);
+            $prodid = mt_rand(1, $num_prods);
             $line->fk_product=$prodids[$prodid];
 
             $this->lines[$xnbp]=$line;