diff --git a/lib/internal/Magento/Framework/Math/Random.php b/lib/internal/Magento/Framework/Math/Random.php
index ca242b5163a321ab2c4b20d9a1338ff323da0807..8ed28cb6021a976337e2e8b9cd6da0c5a98d724c 100644
--- a/lib/internal/Magento/Framework/Math/Random.php
+++ b/lib/internal/Magento/Framework/Math/Random.php
@@ -53,6 +53,10 @@ class Random
                 $str .= $chars[$rand]; // random character in $chars
             }
             fclose($fp);
+        } else {
+            throw new \Magento\Framework\Exception\LocalizedException(
+                new \Magento\Framework\Phrase("Please make sure you have 'openssl' extension installed")
+            );
         }
 
         return $str;
@@ -85,6 +89,10 @@ class Random
             $hex = bin2hex($bytes); // hex() doubles the length of the string
             $offset = abs(hexdec($hex) % $range); // random integer from 0 to $range
             fclose($fp);
+        } else {
+            throw new \Magento\Framework\Exception\LocalizedException(
+                new \Magento\Framework\Phrase("Please make sure you have 'openssl' extension installed")
+            );
         }
 
         return $min + $offset; // random integer from $min to $max