diff --git a/dev/generate-societe.php b/dev/generate-societe.php
index f38f2e95cd13fe2339a990bf4c2c8f511ca0450c..a26a44006275e888e6ec9eb7ec44cc7559d3f60d 100644
--- a/dev/generate-societe.php
+++ b/dev/generate-societe.php
@@ -26,6 +26,11 @@
 		\version    $Revision$
 */
 
+if (! file_exists("../htdocs/master.inc.php"))
+{
+	print "Error: This script must be run from its directory.\n"; 
+	exit -1;	
+}
 require ("../htdocs/master.inc.php");
 include_once(DOL_DOCUMENT_ROOT."/societe.class.php");
 include_once(DOL_DOCUMENT_ROOT."/contact.class.php");
@@ -65,17 +70,21 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
     $soc->nom = "Soci�t� al�atoire num ".time()."$s";
     $villes = array("Auray","Baden","Vannes","Pirouville","Haguenau","Souffelweiersheim","Illkirch-Graffenstaden","Lauterbourg","Picauville","Sainte-M�re Eglise","Le Bono");
     $soc->ville = $villes[rand(0,sizeof($villes)-1)];
-    $soc->client = 1;
+	// Une societe sur 2 est prospect, l'autre client
+    $soc->client = rand(1,2);
+    // Un client sur 10 a une remise de 5%
+    $user_remise=rand(1,10); if ($user_remise==10) $soc->remise_client=5;
+	print "(client=".$soc->client.", remise=".$soc->remise_client.")\n";
     $socid = $soc->create();
 
-    if ($socid)
+    if ($socid >= 0)
     {
         $rand = rand(1,4);
-        print "-- g�n�re $rand contact<br>";
+        print "-- G�n�re $rand contact\n";
         for ($c = 0 ; $c < $rand ; $c++)
         {
             $contact = new Contact($db);
-            $contact->socid = $socid;
+            $contact->socid = $soc->id;
             $contact->nom = "Nom al�a ".time()."-$c";
             if ( $contact->create($user) )
             {
@@ -83,6 +92,10 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
             }
         }
     }
+    else
+    {
+    	print "Error: ".$soc->error."\n";
+    }
 }