/* ECE420, Lab 4, Reference PN Generator Implementation (Non-Optimized) */
/* Matt Kleffner 08/04                                                  */
/* Original by Michael Frutiger 02/24/04                                */
/* Use governed by the Creative Commons Attribution License             */

/* Returns as an integer a random bit, based on the 15 lowest significant
   bits in iseed (which is modified for the next call). */
int randbit(unsigned int *iseed)
{
   int newbit;
   /* XOR bits 15, 1 and 0 of iseed */
   newbit =  (*iseed >> 15) & 1 ^ (*iseed >> 1) & 1 ^ *iseed & 1;
   /* Leftshift the seed and put the result of the XOR's in bit 1. */
   *iseed=(*iseed << 1) | newbit;  
   return(newbit);
}

int randsample(unsigned int *iseed)
{
   if (randbit(iseed)) return( 32767);
   else                return(-32767);
}
