home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
c
/
rand
< prev
next >
Wrap
Text File
|
1994-03-08
|
2KB
|
105 lines
#ifdef __STDC__
static char sccs_id[] = "@(#) rand.c 1.1 " __DATE__ " HJR";
#else
static char sccs_id[] = "@(#) rand.c 1.1 26/9/90 HJR";
#endif
/* rand.c (c) Copyright 1990 H.Rogers */
#include <stdlib.h>
static unsigned long __state[32] =
{
0x6fdb9cb7, 0x9de8dc3d, 0x093bf9e4, 0x47528c2b, 0xfc263867, 0x53cbf1bf,
0x13618c92, 0x9e0f31b1, 0xcd651ab0, 0x2b52a7e5, 0x2ccdd9bf, 0x30052e2e,
0xb278be81, 0xd634a58b, 0x0a33d2c1, 0xfd42f052, 0xcb2f06f8, 0xa57bb730,
0x4ca963ac, 0x84bf5532, 0xd67ab9e6, 0x6e2d017b, 0x1e17cd99, 0x5891173a,
0x39384a29, 0xe0a0282e, 0x2e5512fc, 0x3093f269, 0x3a6983e6, 0x6b9fdaf3,
0x38b6bbd1, 0xb5e23046
};
static int __st1 = 0, __st2 = 3;
#ifdef __STDC__
void
srand (register long seed)
#else
void
srand (seed)
register long seed;
#endif
{
register int i;
for (i = 0; i < 32; i++)
seed = __state[i] = (seed * 1103515245 + 12345);
__st1 = 0;
__st2 = 3;
for (i = 0; i < ((lrand () ^ seed) & 255); i++);
for (i = 0; i < ((lrand () ^ seed) & 255); i++)
lrand ();
}
#ifdef __STDC__
long
lrand (void)
#else
long
lrand ()
#endif
{
register long i, j;
register int k, l;
i = *((long *) (__state + (k = __st1)));
j = *((long *) (__state + (l = __st2)));
if (i < 0 && j < 0)
i = -i;
__state[l] = (i += j);
__st1 = (k + 1) & 31;
__st2 = (l + 1) & 31;
return ((i >> 1) & RAND_MAX);
}
#ifdef __STDC__
int (rand) (void)
#else
int (rand) ()
#endif
{
return (rand ());
}
#ifdef __STDC__
void (srand48) (register long seed)
#else
void (srand48) (seed)
register long seed;
#endif
{
srand48 (seed);
}
#ifdef __STDC__
long (lrand48) (void)
#else
long (lrand48) ()
#endif
{
return (lrand48 ());
}
#ifdef __STDC__
void (srandom) (register long seed)
#else
void (srandom) (seed)
register long seed;
#endif
{
srandom (seed);
}
#ifdef __STDC__
long (random) (void)
#else
long (random) ()
#endif
{
return (random ());
}