Mail Archives: djgpp-workers/1998/11/15/14:30:22
* new multiplier from K.B. Williams
* auto-initialize if the user forgets to
Comments?
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <pc.h>
#include <go32.h>
#include <libc/farptrgs.h>
static unsigned long long next = 0;
static int srand_called = 0;
int
rand(void)
{
if (!srand_called)
{
unsigned int lsb, msb, tics;
outportb(0x43, 0x00);
lsb = inportb(0x40);
msb = inportb(0x40);
tics = _farpeekl(_dos_ds, 0x46c);
srand(lsb | (msb<<8) || (((long long)tics)<<16));
}
next = next * 6364136223846793005LL + 1;
/* was: next = next * 0x5deece66dLL + 11; */
return (int)((next >> 16) & RAND_MAX);
}
void
srand(unsigned seed)
{
next = seed;
srand_called = 1;
rand();
rand();
rand();
}
- Raw text -