diff --git a/lib/SimpleSAML/XHTML/EMail.php b/lib/SimpleSAML/XHTML/EMail.php
index 19b97a028412b8ec46d21531468937c7252200a8..4c5385e5ef2d1ee1d907add08fe93ed421279b5c 100644
--- a/lib/SimpleSAML/XHTML/EMail.php
+++ b/lib/SimpleSAML/XHTML/EMail.php
@@ -66,7 +66,7 @@ pre {
 		if ($this->subject == NULL) throw new Exception('EMail field [subject] is required and not set.');
 		if ($this->body == NULL) throw new Exception('EMail field [body] is required and not set.');
 		
-		$random_hash = substr(0, 16, md5(date('r', time())));
+		$random_hash = SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(16));
 		
 		if (isset($this->from))
 			$this->headers[]= 'From: ' . $this->from;