bytes for filenames elsewhere, too.
diff --git a/OpenSSL/rand.py b/OpenSSL/rand.py
index 8c1a257..b3f7f6b 100644
--- a/OpenSSL/rand.py
+++ b/OpenSSL/rand.py
@@ -140,7 +140,7 @@
                      to read the entire file
     :return: The number of bytes read
     """
-    if not isinstance(filename, str):
+    if not isinstance(filename, _builtin_bytes):
         raise TypeError("filename must be a string")
 
     if maxbytes is _unspecified:
@@ -159,7 +159,7 @@
     :param filename: The file to write data to
     :return: The number of bytes written
     """
-    if not isinstance(filename, str):
+    if not isinstance(filename, _builtin_bytes):
         raise TypeError("filename must be a string")
 
     return _lib.RAND_write_file(filename)