diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index c4d9ae043be5a2c6d0c2a72f40b98340c42d4a84..601ff46caa7c2a4f1da6e7fd0e4242b0e30486ea 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1122,7 +1122,11 @@ class SimpleSAML_Utilities {
 		assert('is_int($length)');
 
 		if($fp === NULL) {
-			$fp = @fopen('/dev/urandom', 'rb');
+			if (file_exists('/dev/urandom')) {
+				$fp = fopen('/dev/urandom', 'rb');
+			} else {
+				$fp = FALSE;
+			}
 		}
 
 		if($fp !== FALSE) {