source: golgotha/src/i4/math/random.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.1 KB
RevLine 
[80]1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "arch.hh"
10
11enum { TSIZE=512 };
12static w32   w32_rtable[TSIZE];
13static float f_rtable[TSIZE];
14static int seed=0;
15static int initialized=0;
16
17void next_seed()
18{
19  if (!initialized)
20  {
21    w32 inc=0xacd2d391, mul=0xf34f9201, x=0;
22    for (int i=0; i<TSIZE; i++)
23    {     
24      w32_rtable[i]=x;
25      f_rtable[i]=(double)x/(double)0xffffffff;
26      x=(x+inc)*mul;
27    }
28    initialized=1;
29  }
30
31  seed++; 
32}
33
34w32 i4_rand()
35{
36  next_seed();
37  return w32_rtable[seed];
38}
39
40float i4_float_rand()
41{
42  next_seed();
43  return f_rtable[seed];
44}
45
46void i4_rand_reset(w32 _seed)
47{
48  seed=_seed % TSIZE;
49}
50
Note: See TracBrowser for help on using the repository browser.