Difference between revisions of "Source:Hack 1.0/rnd.c"

From NetHackWiki
Jump to navigation Jump to search
m (Automated source code upload)
 
(Part 15 has been found; replace content with the rnd.c from part 15)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
Below is the full text to '''rnd.c''' from the [[Hack 1.0 source code|source code]] of [[Hack 1.0]]. To link to a particular line, write [[Hack 1.0/rnd.c#line123|<nowiki>[[Hack 1.0/rnd.c#line123]]</nowiki>]], for example.
 
Below is the full text to '''rnd.c''' from the [[Hack 1.0 source code|source code]] of [[Hack 1.0]]. To link to a particular line, write [[Hack 1.0/rnd.c#line123|<nowiki>[[Hack 1.0/rnd.c#line123]]</nowiki>]], for example.
  
'''Warning!''' This is the source code from an old release. For the latest release, see [[Source code]]
+
'''Warning!''' This is the source code from an old release. For the latest release, see [[Source code]].
  
 
{{CWI}}
 
{{CWI}}
Line 7: Line 7:
 
  <span id="line2">2.    </span>
 
  <span id="line2">2.    </span>
 
  <span id="line3">3.    rn1(x,y)</span>
 
  <span id="line3">3.    rn1(x,y)</span>
  <span id="line4">4.    register int x,y;</span>
+
  <span id="line4">4.    register x,y;</span>
 
  <span id="line5">5.    {</span>
 
  <span id="line5">5.    {</span>
 
  <span id="line6">6.    return(RND(x)+y);</span>
 
  <span id="line6">6.    return(RND(x)+y);</span>
Line 13: Line 13:
 
  <span id="line8">8.    </span>
 
  <span id="line8">8.    </span>
 
  <span id="line9">9.    rn2(x)</span>
 
  <span id="line9">9.    rn2(x)</span>
  <span id="line10">10.  register int x;</span>
+
  <span id="line10">10.  register x;</span>
 
  <span id="line11">11.  {</span>
 
  <span id="line11">11.  {</span>
 
  <span id="line12">12.  return(RND(x));</span>
 
  <span id="line12">12.  return(RND(x));</span>
Line 19: Line 19:
 
  <span id="line14">14.  </span>
 
  <span id="line14">14.  </span>
 
  <span id="line15">15.  rnd(x)</span>
 
  <span id="line15">15.  rnd(x)</span>
  <span id="line16">16.  register int x;</span>
+
  <span id="line16">16.  register x;</span>
 
  <span id="line17">17.  {</span>
 
  <span id="line17">17.  {</span>
 
  <span id="line18">18.  return(RND(x)+1);</span>
 
  <span id="line18">18.  return(RND(x)+1);</span>
Line 25: Line 25:
 
  <span id="line20">20.  </span>
 
  <span id="line20">20.  </span>
 
  <span id="line21">21.  d(n,x)</span>
 
  <span id="line21">21.  d(n,x)</span>
  <span id="line22">22.  register int n,x;</span>
+
  <span id="line22">22.  register n,x;</span>
 
  <span id="line23">23.  {</span>
 
  <span id="line23">23.  {</span>
  <span id="line24">24.  register int tmp = n;</span>
+
  <span id="line24">24.  register tmp = n;</span>
 
  <span id="line25">25.  </span>
 
  <span id="line25">25.  </span>
 
  <span id="line26">26.  while(n--) tmp += RND(x);</span>
 
  <span id="line26">26.  while(n--) tmp += RND(x);</span>

Latest revision as of 05:35, 31 October 2014

Below is the full text to rnd.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/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.    #define RND(x)	((rand()>>3) % x)
2.    
3.    rn1(x,y)
4.    register x,y;
5.    {
6.    	return(RND(x)+y);
7.    }
8.    
9.    rn2(x)
10.   register x;
11.   {
12.   	return(RND(x));
13.   }
14.   
15.   rnd(x)
16.   register x;
17.   {
18.   	return(RND(x)+1);
19.   }
20.   
21.   d(n,x)
22.   register n,x;
23.   {
24.   	register tmp = n;
25.   
26.   	while(n--) tmp += RND(x);
27.   	return(tmp);
28.   }