home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 002.lha / rnd.s < prev    next >
Text File  |  1986-05-05  |  1KB  |  42 lines

  1. *\ RND.S                                              From: AMIGA.4340
  2. *  :ts=8
  3. * Yet Another random number generator.  By Leo Schwab.
  4. * Based on an idea posted on the USENET (Thanks, Sam Dicker!)
  5. * For the Manx assembler.
  6. *
  7. * Calling convention:
  8. *  short rnd (range);
  9. *  short range;
  10. *
  11. * 8606.30
  12. */
  13.  
  14.                 public    _rnd
  15.  
  16. _rnd            lea     rndseed,a0      Get address of seed
  17.                 move.w  4(sp),d1        Get range argument
  18.                 tst.w   d1
  19.                 ble.s   setseed         Go reset seed
  20.  
  21.  
  22.                 move.l  (a0),d0         Get seed
  23.                 ADD.L   D0,D0
  24.                 BHI.S   over
  25.                 EORI.L  #$1D872B41,D0
  26. over
  27.                 move.l  d0,(a0)         Save new seed
  28.                 andi.l  #$ffff,d0       Coerce into word
  29.                 divu    d1,d0           Divide by range
  30.                 swap    d0               and get remainder (modulus)
  31.                 rts
  32.  
  33. setseed         neg.w   d1              Probably don't need this
  34.                 move.l  d1,(a0)
  35.                 rts
  36.  
  37.                 dseg
  38. rndseed         dc.l    0
  39.                 cseg
  40.  
  41.                 end
  42.