home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / apl / af.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-23  |  741 b   |  56 lines

  1. #include "apl.h"
  2. #include <stdlib.h>
  3. #include <limits.h>
  4.  
  5.  
  6. ex_deal()
  7. {
  8.     struct item *p;
  9.     int m, n;
  10.     double f;
  11.     data d1, d2;
  12.  
  13.     m = topfix();
  14.     n = topfix();
  15.     if(m < 0 || m > n) error("deal D");
  16.     p = newdat(DA, 1, m);
  17.     datum = thread.iorg;
  18.     for(; n!=0; n--) {
  19.         f = m;
  20.         f /= n;
  21.         if(random()/(float)INT_MAX < f) {
  22.             putdat(p, datum);
  23.             m--;
  24.         }
  25.         datum += one;
  26.     }
  27.     m = p->size;
  28.     while(m > 0) {
  29.         f = random()/(float)INT_MAX;
  30.         n = m * f;
  31.         m--;
  32.         if(n != m) {
  33.             p->index = n;
  34.             d1 = getdat(p);
  35.             p->index = m;
  36.             d2 = getdat(p);
  37.             p->index = n;
  38.             putdat(p, d2);
  39.             p->index = m;
  40.             putdat(p, d1);
  41.         }
  42.     }
  43.     *sp++ = p;
  44. }
  45.  
  46. data
  47. ex_rand(d)
  48. data d;
  49. {
  50.     double f;
  51.  
  52.     f = (random()/(float)INT_MAX) * d;
  53.     d = floor(f) + thread.iorg;
  54.     return(d);
  55. }
  56.