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

  1.     page    66,132
  2. ;******************************* RANDOM5.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_WORD3 - generate random word value, using method 3
  15. ;
  16. ;  inputs:  AX = range of random numbers -1
  17. ;  output:  AX = random number
  18. ;         
  19. * * * * * * * * * * * * * *
  20. 
  21.  
  22. rand_seed    dd    ?
  23. scale_factor        dw    16
  24.  
  25. loop_count = 16
  26. ;----------------------------------
  27.  
  28.     public    RANDOM_WORD3
  29. RANDOM_WORD3    proc    far
  30.     mov    bx,word ptr [rand_seed]
  31.     mov    ax,word ptr [rand_seed+2]
  32.     mov    cx,loop_count
  33. r3_lp:  mov    dl,bl
  34.     test    ah,0EAh
  35.     jpe    lp_tail
  36.     xor dl,1       
  37. lp_tail:shr    dl,1
  38.     adc    bx,bx
  39.     adc    ax,ax
  40.     dec    cx
  41.     jnz    r3_lp
  42.  
  43.     mov    word ptr [rand_seed],bx
  44.     mov    word ptr [rand_seed+2],ax
  45.   
  46.     mov    cx,[scale_factor]
  47.     xor    dx,dx
  48.     cmp    cx,1
  49.     jbe    rd_end
  50.     div    cx
  51.     mov    ax,bx
  52.     div    cx
  53. rd_end:    mov ax,dx
  54.     retf
  55. RANDOM_WORD3    endp
  56.  
  57. LIBSEG    ENDS
  58. ;;    end
  59.