home *** CD-ROM | disk | FTP | other *** search
/ Chip Hitware 7 / Chip_Hitware_Vol_07.iso / chiphit7 / spiele / bgpro / elkins.c_ / elkins.c
Encoding:
C/C++ Source or Header  |  1996-01-26  |  1.2 KB  |  74 lines

  1. #include "windows.h"
  2. #include "stdlib.h"
  3. #include "stdio.h"
  4. #include "bios.h"
  5.  
  6. #include "elkins.h"
  7.  
  8. static unsigned short s[3]={100, 1000, 10000};
  9. static unsigned short f[3]={179, 183, 182};
  10. static unsigned short m[3]={32771, 32779, 32783};
  11.  
  12.  
  13.  
  14. static void Randomize(void)
  15. {
  16.     unsigned long ulTime;
  17.  
  18.     _bios_timeofday(_TIME_GETCLOCK, (long *) &ulTime);
  19.  
  20.     s[0]=(unsigned short) (ulTime&0xFF);
  21.     if (s[0]==0)
  22.     {
  23.         s[0]=0x55;
  24.     }
  25.     s[1]=(unsigned short) ((ulTime>>8)&0xFF);
  26.     if (s[1]==0)
  27.     {
  28.         s[1]=0x66;
  29.     }
  30.     s[2]=(unsigned short) ((ulTime>>16)&0xFF);
  31.     if (s[2]==0)
  32.     {
  33.         s[2]=0x77;
  34.     }
  35. }
  36.  
  37. unsigned short _export __far __pascal GetRandom(unsigned short usMod)
  38. {
  39.     int fRedo, i;
  40.     unsigned short usVal, usDivRest;
  41.  
  42.     do
  43.     {
  44.         fRedo=0;
  45.         usVal=0;
  46.         for(i=0; i<3; i++)
  47.         {
  48.             usDivRest=(unsigned short) (((unsigned long) s[i]*f[i])%m[i]);
  49.             s[i]=usDivRest;
  50.             usDivRest-=1;
  51.             fRedo|=(usDivRest>=32767);
  52.             usVal+=usDivRest;
  53.         }
  54.     } while(fRedo);
  55.  
  56.     usVal&=32767;
  57.     return usVal%usMod;
  58. }
  59.  
  60. int FAR PASCAL LibMain( HINSTANCE hInstance, WORD wDataSegment,
  61.                                    WORD wHeapSize, LPSTR lpszCmdLine )
  62. {
  63.     if ( wHeapSize != 0 )
  64.         UnlockData( 0 );
  65.  
  66.     Randomize();
  67.     return 1;
  68. }
  69.  
  70. int FAR PASCAL WEP ( int bSystemExit )
  71. {
  72.     return 1;
  73. }
  74.