home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / bytewarp.zip / MISC.C < prev    next >
C/C++ Source or Header  |  1995-11-30  |  2KB  |  86 lines

  1.  
  2. /*
  3. ** misc.c
  4. ** BYTEmark (tm)
  5. ** BYTE's Native Mode Benchmarks
  6. ** Rick Grehan, BYTE Magazine
  7. ** DISCLAIMER
  8. ** The source, executable, and documentation files that comprise
  9. ** the BYTEmark benchmarks are made available on an "as is" basis.
  10. ** This means that we at BYTE Magazine have made every reasonable
  11. ** effort to verify that the there are no errors in the source and
  12. ** executable code.  We cannot, however, guarantee that the programs
  13. ** are error-free.  Consequently, McGraw-HIll and BYTE Magazine make
  14. ** no claims in regard to the fitness of the source code, executable
  15. ** code, and documentation of the BYTEmark.
  16. **  Furthermore, BYTE Magazine, McGraw-Hill, and all employees
  17. ** of McGraw-Hill cannot be held responsible for any damages resulting
  18. ** from the use of this code or the results obtained from using
  19. ** this code.
  20. */
  21.  
  22. #include <stdio.h>
  23. #include "misc.h"
  24.  
  25. /***********************************************************
  26. **     MISCELLANEOUS BUT OTHERWISE NECESSARY ROUTINES     **
  27. ***********************************************************/
  28.  
  29. /****************************
  30. ** RANDOM NUMBER GENERATOR **
  31. *****************************
  32. ** This is a second-order linear congruential random number
  33. ** generator.  Its advantage is (of course) that it can be
  34. ** seeded and will thus produce repeatable sequences of
  35. ** random numbers.
  36. */
  37.  
  38. /****************************
  39. *         randwc()          *
  40. *****************************
  41. ** Returns signed long random modulo num.
  42. */
  43. long randwc(long num)
  44. {
  45.     return(randnum(0L)%num);
  46. }
  47.  
  48. /***************************
  49. **      abs_randwc()      **
  50. ****************************
  51. ** Same as randwc(), only this routine returns only
  52. ** positive numbers.
  53. */
  54. unsigned long abs_randwc(unsigned long num)
  55. {
  56. long temp;        /* Temporary storage */
  57.  
  58. temp=randwc(num);
  59. if(temp<0) temp=0L-temp;
  60.  
  61. return((unsigned long)temp);
  62. }
  63.  
  64. /****************************
  65. *        randnum()          *
  66. *****************************
  67. ** Second order linear congruential generator.
  68. ** Constants suggested by J. G. Skellam.
  69. ** If val==0, returns next member of sequence.
  70. **    val!=0, restart generator.
  71. */
  72. long randnum(long lngval)
  73. {
  74.     register long interm;
  75.     static long randw[2] = { 13L , 117L };
  76.  
  77.     if (lngval!=0L)
  78.     {    randw[0]=13L; randw[1]=117L; }
  79.  
  80.     interm=(randw[0]*254754L+randw[1]*529562L)%999563L;
  81.     randw[1]=randw[0];
  82.     randw[0]=interm;
  83.     return(interm);
  84. }
  85.  
  86.