ftp.nice.ch/pub/next/unix/communication/ppp_2_2.0.4.6.s.tar.gz#/NeXT/random.c

This is random.c in view mode; [Download] [Up]

/*
 * Because the standard library random number
 * functions are not availble at the kernel level
 * I wrote this simple random number generator.
 *
 * It uses the multiplicative congruential method.
 * See pg 263 of Banks and Carson "Discrete-Event
 * System Simulation".
 *
 */

#include "random.h"

static unsigned x0=123457;     /* seed */
static unsigned a=16807;       /* constant multiplier */
static unsigned c=0;           /* increment */
static unsigned m=2147483647;  /* modulus */

/*
 * Set the seed to the argument.
 */

void srand(unsigned i)
{
  x0 = i;
}


/*
 * Use Linear Congruential Method to Generate
 * sequence.  Return either int or float...
 */
  
unsigned rand(void)
{
  unsigned tmpseed;

  tmpseed = (a*x0+c) % m;
  x0 = tmpseed;
  return (unsigned) x0;
}



float frand(void)
{
  unsigned tmpseed;

  tmpseed = (a*x0+c) % m;
  x0 = tmpseed;
  return (x0/(float)m);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.