diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 7954e8a..3d79fe5 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1731,11 +1731,12 @@
     ASSERT(rand_bytes(output, len));
 }
 
-/* an analogue to the random() function, but use prng_bytes */
-long int
+/* an analogue to the random() function, but use prng_bytes and
+ * also int64_t instead of long to avoid LLP64 vs LP64 */
+int64_t
 get_random(void)
 {
-    long int l;
+    int64_t l;
     prng_bytes((unsigned char *)&l, sizeof(l));
     if (l < 0)
     {
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index fbca2a0..ee5b50f 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -603,8 +603,13 @@
  */
 void prng_bytes(uint8_t *output, int len);
 
-/* an analogue to the random() function, but use prng_bytes */
-long int get_random(void);
+/**
+ * an analogue to the random() function, but use prng_bytes and
+ * also int64_t instead of long to avoid LLP64 vs LP64
+ *
+ * @return Returns a random positive 63 bit integer
+ */
+int64_t get_random(void);
 
 /** Print a cipher list entry */
 void print_cipher(const char *cipher);
diff --git a/src/openvpn/platform.c b/src/openvpn/platform.c
index 9fa9363..85b6408 100644
--- a/src/openvpn/platform.c
+++ b/src/openvpn/platform.c
@@ -543,7 +543,7 @@
     const char *retfname = NULL;
     unsigned int attempts = 0;
     char fname[256] = { 0 };
-    const char *fname_fmt = PACKAGE "_%.*s_%08lx%08lx.tmp";
+    const char *fname_fmt = PACKAGE "_%.*s_%08" PRIx64 "%08" PRIx64 ".tmp";
     const int max_prefix_len = sizeof(fname) - (sizeof(PACKAGE) + 7 + (2 * 8));
 
     while (attempts < 6)
@@ -551,7 +551,7 @@
         ++attempts;
 
         if (!checked_snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len, prefix,
-                              (unsigned long)get_random(), (unsigned long)get_random()))
+                              get_random(), get_random()))
         {
             msg(M_WARN, "ERROR: temporary filename too long");
             return NULL;
