Metropoli BBS
VIEWER: random.asm MODE: TEXT (CP437)
;                  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 USES EBX EDX
Public Random
        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
	ret
align 4

Initalize_Random_number:            ; Get inital random number from CMOS time

        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
        push    es
        xor     ax,ax                       ; GET DOS32 selector values
        int     31h
        shr     ebx,16
        mov     es,bx
        xor     eax,es:[046Ch]             ; through in number of ticks
        pop     es
        not     eax
        mov     Random_init,eax
        jmp J75


Random_init     dd 0
;────────────────────────────────────────────────────────────────────────────
Random  Endp

        End

[ RETURN TO DIRECTORY ]