shithub: qk1

Download patch

ref: b64d816a6b39760ca8df9434d7277bf8babe55b3
parent: 28eafdc8ebdc8f0c05196cc45cc9bb38ae4550a6
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Nov 25 21:33:01 EST 2023

better PF_random

--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -442,11 +442,20 @@
 */
 void PF_random (pr_t *pr)
 {
-	float		num;
+	static double xmax;
+	static long xand;
 
-	num = (rand ()&0x7fff) / ((float)0x7fff);
+	if(xand == 0){
+		if((RAND_MAX & ((ulong)RAND_MAX+1)) == 0){
+			xmax = (ulong)RAND_MAX+1;
+			xand = RAND_MAX;
+		}else{
+			xmax = 0x8000;
+			xand = 0x7fff;
+		}
+	}
 
-	G_FLOAT(pr, OFS_RETURN) = num;
+	G_FLOAT(pr, OFS_RETURN) = ((double)(rand() & xand) + 0.5) / xmax;
 }
 
 /*