home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / LIB / RANDOM.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-11  |  2.0 KB  |  79 lines

  1. ;                  library file for DOS32 32bit DOS extender
  2. ;        Writen by Adam Seychell
  3.  
  4.  
  5. .386
  6. .Model flat, Pascal
  7.  
  8. .CODE
  9.  
  10. comment $
  11. ╔═══════════════════════════════════════════════════════════════════════╗
  12. ║ Returns EAX with a random number with CL bits in size.                ║
  13. ║                                                                       ║
  14. ║   The algorithem was from an article in Doctor Dobbs Journal          ║
  15. ║   issue date  MAY 1991                                                ║
  16. ║                                                                       ║
  17. ║  NOTE: the initial random number is taken from the CMOS clock         ║
  18. ╚═══════════════════════════════════════════════════════════════════════╝$
  19. Random PROC
  20. Public Random
  21.         push edx
  22.         push ebx 
  23.         xor eax,eax
  24.         cmp eax,random_init
  25.         je Initalize_Random_number
  26. J75:
  27.         mov bl,byte ptr random_init
  28.         and bl,1
  29.  
  30. Gen_bit:    ; make n bit numbers
  31.         shl eax,1
  32.  
  33.     mov edx,Random_init
  34.  
  35.         shr edx,9
  36.         xor bl,dl
  37.  
  38.         shr edx,5
  39.         xor bl,dl
  40.  
  41.         bt ebx,1
  42.     rcr Random_init,1
  43.         setc bl
  44.     or  al,bl
  45.  
  46.     dec cl
  47.         jnz Gen_bit
  48.         pop ebx
  49.         pop edx
  50.     ret
  51. align 4
  52. Random_init     dd 0
  53.  
  54. Initalize_Random_number:            ; Get inital random number from CMOS time
  55.  
  56.         push    es
  57.         mov     ax,0EE00h               ; GET DOS32 selector values
  58.         int     31h
  59.         mov     es,bx
  60.  
  61.         mov     al,0                    ; Get seconds
  62.         out     70h,al
  63.         in      al,71h
  64.         shl     eax,8
  65.         mov     al,2                    ; Get minute
  66.         out     70h,al
  67.         in      al,71h
  68.         shl     eax,8
  69.         xor     eax,es:[046Ch]             ; throw in number of ticks
  70.         pop     es
  71.         not     eax
  72.         mov     Random_init,eax
  73.         jmp J75
  74.  
  75. ;────────────────────────────────────────────────────────────────────────────
  76. Random  Endp
  77.  
  78.         End
  79.