Source:NetHack 1.4f/rnd.c

Below is the full text to rnd.c from the source code of NetHack 1.4f. To link to a particular line, write [[NetHack 1.4f/rnd.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)rnd.c	1.4	87/08/08 2.   /* rnd.c - version 1.0.2 */ 3.    4.    #define RND(x)	((rand>>3) % x)  5. 6.   rn1(x,y)	/* y <= rn1(x,y) < (y+x) */ 7.   register x,y; 8.   {  9.    	return(RND(x)+y); 10.  }  11.    12.   rn2(x)		/* 0 <= rn2(x) < x */ 13.  register x;  14. { 15.   	return(RND(x)); 16.  }  17.    18.   rnd(x)		/* 1 <= rnd(x) <= x */ 19.  register x;  20. { 21.   	return(RND(x)+1); 22.  }  23.    24.   d(n,x)		/* n <= d(n,x) <= (n*x) */ 25.  register n,x; 26.  {  27.   	register tmp = n;  28. 29.  	while(n--) tmp += RND(x); 30.  	return(tmp); 31.  }  32.    33.   rne(x)          /* by stewr 870807 */ 34.  register x;  35. { 36.           register tmp = 1; 37.  	while(!rn2(x)) tmp++; 38.  	return(tmp); 39.  }  40.    41.   rnz(x) 42.  register x;  43. { 44.           register tmp = 1000; 45.  	tmp += rn2(1000); 46.  	tmp *= rne(4); 47.  	if (rn2(2)) { x *= tmp; x /= 1000; } 48.  	else { x *= 1000; x /= tmp; } 49.  	return(x); 50.  }