1diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
2index e272cba..3a1fa71 100644
3--- a/ext/openssl/extconf.rb
4+++ b/ext/openssl/extconf.rb
5@@ -87,6 +87,7 @@
6 have_func("PEM_def_callback")
7 have_func("PKCS5_PBKDF2_HMAC")
8 have_func("PKCS5_PBKDF2_HMAC_SHA1")
9+have_func("RAND_egd")
10 have_func("X509V3_set_nconf")
11 have_func("X509V3_EXT_nconf_nid")
12 have_func("X509_CRL_add0_revoked")
13diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c
14index 29cbf8c..27466fe 100644
15--- a/ext/openssl/ossl_rand.c
16+++ b/ext/openssl/ossl_rand.c
17@@ -148,6 +148,7 @@ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
18 return str;
19 }
20
21+#ifdef HAVE_RAND_EGD
22 /*
23 * call-seq:
24 * egd(filename) -> true
25@@ -186,6 +187,7 @@ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
26 }
27 return Qtrue;
28 }
29+#endif /* HAVE_RAND_EGD */
30
31 /*
32 * call-seq:
33@@ -219,8 +221,10 @@ Init_ossl_rand(void)
34 rb_define_module_function(mRandom, "write_random_file", ossl_rand_write_file, 1);
35 rb_define_module_function(mRandom, "random_bytes", ossl_rand_bytes, 1);
36 rb_define_module_function(mRandom, "pseudo_bytes", ossl_rand_pseudo_bytes, 1);
37+#ifdef HAVE_RAND_EGD
38 rb_define_module_function(mRandom, "egd", ossl_rand_egd, 1);
39 rb_define_module_function(mRandom, "egd_bytes", ossl_rand_egd_bytes, 2);
40+#endif /* HAVE_RAND_EGD */
41 rb_define_module_function(mRandom, "status?", ossl_rand_status, 0);
42 }