diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c
index 73ebf896b6851991009827fdfb0bcc09fb72afb4..2b4db87f3ccf67e223f251c7cc60c0a758710d59 100644
--- a/src/xpdev/genwrap.c
+++ b/src/xpdev/genwrap.c
@@ -327,7 +327,7 @@ long DLLCALL xp_random(int n)
 	if(n<2)
 		return(0);
 
-	limit = ((1U<<((sizeof(long)*CHAR_BIT)-1)) / n) * n - 1;
+	limit = ((1UL<<((sizeof(long)*CHAR_BIT)-1)) / n) * n - 1;
 
 	while(1) {
 		curr=random();