diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php
index b9af45d2c5c3dfab48caa6267bd34f6f4e121cd7..f201275b500676c6503ae27e38c5960c703e9f4d 100644
--- a/ecrire/public/criteres.php
+++ b/ecrire/public/criteres.php
@@ -346,7 +346,7 @@ function critere_parinverse($idb, &$boucles, $crit, $sens='') {
 			$order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens);
 			// et ajouter un champ hasard dans le select 
 			//pour supporter 'hasard' comme tri dynamique
-			$par = "UNIX_TIMESTAMP()";
+			$par = "rand()";
 			$boucle->select[]= $par . " AS hasard";
 	  } else {
 	      $par = array_shift($tri);
@@ -372,7 +372,7 @@ function critere_parinverse($idb, &$boucles, $crit, $sens='') {
 		if (count($match)>2) { $par = substr($match[2],1,-1); $fct = $match[1]; }
 	// par hasard
 		if ($par == 'hasard') {
-			$par = "UNIX_TIMESTAMP()";
+			$par = "rand()";
 		  $boucle->select[]= $par . " AS alea";
 		  $order = "'alea'";
 		}
diff --git a/ecrire/req/pg.php b/ecrire/req/pg.php
index d87fd70137d6463055027f9aa5147cc19107e4a0..76a1600008a9f2a344719b06e88e39b0b9c5b534 100644
--- a/ecrire/req/pg.php
+++ b/ecrire/req/pg.php
@@ -334,6 +334,7 @@ function spip_pg_frommysql($arg)
 
 	$res = spip_pg_fromfield($arg);
 
+	$res = preg_replace('/\brand[(][)]/','random()', $res);
 	$res = preg_replace('/\b0\.0[+]([^, ]+)\s*/',
 			    'CAST(substring(\1, \'^ *[0-9.]+\') as float)',
 			    $res);