Fandom

Wikihack

Source:NetHack 2.2a/rnd.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

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

Screenshots and source code from Hack are used under the CWI license.
1.    /*	SCCS Id: @(#)rnd.c	2.0	87/09/15
2.     */
3.    #include	"config.h"
4.    #ifdef UNIX
5.    #define RND(x)	(random() % (x))
6.    #else
7.    /* Good luck: the bottom order bits are cyclic. */
8.    #define RND(x)	((rand()>>3) % (x))
9.    #endif
10.   
11.   rn1(x,y)	/* y <= rn1(x,y) < (y+x) */ 
12.   register x,y;
13.   {
14.   	return(RND(x)+y);
15.   }
16.   
17.   rn2(x)		/* 0 <= rn2(x) < x */
18.   register x;
19.   {
20.   	return(RND(x));
21.   }
22.   
23.   rnd(x)		/* 1 <= rnd(x) <= x */
24.   register x;
25.   {
26.   	return(RND(x)+1);
27.   }
28.   
29.   d(n,x)		/* n <= d(n,x) <= (n*x) */
30.   register n,x;
31.   {
32.   	register tmp = n;
33.   
34.   	while(n--) tmp += RND(x);
35.   	return(tmp);
36.   }
37.   
38.   rne(x)          /* by stewr 870807 */
39.   register x;
40.   {
41.           register tmp = 1;
42.   	while(!rn2(x)) tmp++;
43.   	return(tmp);
44.   }
45.   
46.   rnz(x)
47.   register x;
48.   {
49.           register tmp = 1000;
50.   	tmp += rn2(1000);
51.   	tmp *= rne(4);
52.   	if (rn2(2)) { x *= tmp; x /= 1000; }
53.   	else { x *= 1000; x /= tmp; }
54.   	return(x);
55.   }

Also on Fandom

Random Wiki