home *** CD-ROM | disk | FTP | other *** search
- ; library file for DOS32 32bit DOS extender
- ; Writen by Adam Seychell
-
-
- .386
- .Model flat, Pascal
-
- .CODE
-
- comment $
- ╔═══════════════════════════════════════════════════════════════════════╗
- ║ Returns EAX with a random number with CL bits in size. ║
- ║ ║
- ║ The algorithem was from an article in Doctor Dobbs Journal ║
- ║ issue date MAY 1991 ║
- ║ ║
- ║ NOTE: the initial random number is taken from the CMOS clock ║
- ╚═══════════════════════════════════════════════════════════════════════╝$
- Random PROC
- Public Random
- push edx
- push ebx
- xor eax,eax
- cmp eax,random_init
- je Initalize_Random_number
- J75:
- mov bl,byte ptr random_init
- and bl,1
-
- Gen_bit: ; make n bit numbers
- shl eax,1
-
- mov edx,Random_init
-
- shr edx,9
- xor bl,dl
-
- shr edx,5
- xor bl,dl
-
- bt ebx,1
- rcr Random_init,1
- setc bl
- or al,bl
-
- dec cl
- jnz Gen_bit
- pop ebx
- pop edx
- ret
- align 4
- Random_init dd 0
-
- Initalize_Random_number: ; Get inital random number from CMOS time
-
- push es
- mov ax,0EE00h ; GET DOS32 selector values
- int 31h
- mov es,bx
-
- mov al,0 ; Get seconds
- out 70h,al
- in al,71h
- shl eax,8
- mov al,2 ; Get minute
- out 70h,al
- in al,71h
- shl eax,8
- xor eax,es:[046Ch] ; throw in number of ticks
- pop es
- not eax
- mov Random_init,eax
- jmp J75
-
- ;────────────────────────────────────────────────────────────────────────────
- Random Endp
-
- End