home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / RANDOM2.ASM < prev    next >
Assembly Source File  |  1994-11-14  |  1KB  |  61 lines

  1.     page    66,132
  2. ;******************************* RANDOM2.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( RANDOM  )
  14. RANDOM_WORD2 -  generate random word value, using method 2
  15. ;
  16. ; inputs: (ds:bx)  struc
  17. ;                   rs1   dw  (random seed 1)
  18. ;                   rs2   dw  (random seed 2)
  19. ;                   range dw  mask to truncate number, normally a power
  20. ;                             of 2 is used.  Example  1fh, 1ffh, 3ffh, etc.
  21. ;                   
  22. ; output:  ax = random number
  23. ;
  24. ; note:  RANDOM_WORD2 is designed for applications which need to keep several
  25. ;        random number sequences going indepently.  The input structure
  26. ;        (ds:bx) can use a different set of data for each random sequence.
  27. ;        
  28. ;* * * * * * * * * * * * * *
  29. 
  30.  
  31. randd    struc
  32. rs1    dw    ?
  33. rs2    dw    ?
  34. range    dw    ?
  35. randd    ends
  36.  
  37. first_random    db    0
  38. ;-------------------------
  39.     public    RANDOM_WORD2
  40. RANDOM_WORD2    proc      far
  41.     mov    dx,[bx.rs2]
  42.     mov    ax,[bx.rs1]
  43.     mov    [bx.rs2],ax
  44.  
  45.     mov    cx,171
  46.     mul    cx
  47.     mov    cx,30269
  48.     div    cx
  49.     mov    ax,dx
  50. ;
  51. ; scale random number
  52. ;
  53. gr_wrap_up:
  54.     mov    [bx.rs1],ax        ;save for next time
  55.     and    ax,[bx.range]        ;scale number
  56.     retf
  57. RANDOM_WORD2    endp
  58.  
  59. LIBSEG    ENDS
  60.     end
  61.