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

  1.     page    66,132
  2. ;******************************* RANDOM3.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.     extrn    random_seed:far
  12. .list
  13. comment 
  14. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( RAMDOM  )
  15. random_byte1 - generate random number
  16. ;  inputs:   none
  17. ;  output:   al = random number
  18. * * * * * * * * * * * * * *
  19. 
  20.  
  21.     PUBLIC random_byte1
  22. random_byte1    proc    FAR
  23.     cmp    cs:init_flag,0
  24.     jne    continue
  25.     call    init_buffer
  26. continue:
  27.     xor    ax,ax
  28.     xor    bx,bx
  29.     mov    bl,ref1
  30.     mov    al,[permute_buffer+bx]
  31.     dec    bl
  32.     jnz    fwd1
  33.     or    bl,62h    
  34. fwd1:    mov    ref1,bl
  35.     mov    bl,ref2
  36.     add    al,[permute_buffer+bx]
  37.     mov    [permute_buffer + bx],al
  38.     dec    bl
  39.     jnz    fwd2
  40.     or    bl,62h
  41. fwd2:    mov    ref2,bl
  42.     mov    bl,ref3
  43.     mov    al,[permute_buffer +bx]
  44.     dec    bl
  45.     jnz    fwd3
  46.     or    bl,61h
  47. fwd3:    mov    ref3,bl
  48.     mov    bl,ref4
  49.     add    al,[permute_buffer + bx]
  50.     dec    bl
  51.     jnz    fwd4
  52.     or    bl,61h
  53. fwd4:    mov    ref4,bl
  54.     retf
  55. random_byte1 endp
  56. ;--------------------------------
  57. permute_buffer     DB    96 DUP (?)             ;permute buffer
  58. ref1          DB    62h
  59. ref2          DB 0bh
  60. ref3          DB 61h
  61. ref4          DB 22h
  62.  
  63. init_flag    db    0
  64.  
  65. ;---------------------------------------
  66.  
  67.     PUBLIC init_buffer
  68. init_buffer proc FAR  ;Load array values
  69.     mov    cx,98        ;size of buffer
  70.     mov    cs:init_flag,1
  71.     call    random_seed
  72. loop1:    xor    bx,bx
  73.     mov    bl,[cs:ref1]
  74.     mov    [cs:permute_buffer+bx],al
  75.     dec    cs:ref1
  76.     jnz    skip
  77.     or    cs:ref1,062h
  78. Skip:    loop    loop1            ;loop 98 times
  79.     ret
  80. init_buffer endp
  81.  
  82. LIBSEG    ENDS
  83. ;;    end
  84.