Last active
December 31, 2019 00:48
-
-
Save NullExceptionTSB/40c6bd69522de2369fae18f4e834444a to your computer and use it in GitHub Desktop.
]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Xorshift32: | |
;state ^= state << 13 | |
;state ^= state >> 17 | |
;state ^= state << 5 | |
xorshift32: | |
push eax | |
mov eax, [state32] | |
shl eax, 13 | |
xor [state32], eax | |
mov eax, [state32] | |
shr eax, 17 | |
xor [state32], eax | |
mov eax, [state32] | |
shl eax, 5 | |
xor [state32], eax | |
pop eax | |
ret | |
;Xorshift16: | |
;state ^= state << 7 | |
;state ^= state >> 9 | |
;state ^= state << 8 | |
xorshift16: | |
push ax | |
mov ax, [state16] | |
shl ax, 7 | |
xor [state16], ax | |
mov ax, [state16] | |
shr ax, 9 | |
xor [state16], ax | |
mov ax, [state16] | |
shl ax, 8 | |
xor [state16], ax | |
pop ax | |
ret | |
;Xorshift8: | |
;state ^= state << 1 | |
;state ^= state >> 1 | |
;state ^= state << 2 | |
xorshift8: | |
push ax | |
mov al, [state8] | |
shl al, 1 | |
xor [state8], al | |
mov al, [state8] | |
shr al, 1 | |
xor [state8], al | |
mov al, [state8] | |
shl al, 2 | |
xor [state8], al | |
pop ax | |
ret | |
;bonus (realmode only!) | |
;seeds prng(s) using int 1Ah AH = 0 | |
;basically like GetTickCount from WinAPI but for realmode | |
seedrng: | |
pushad | |
xor ax, ax | |
int 1Ah | |
mov [state8], dl | |
mov [state16], dx | |
shl ecx, 16 | |
mov cx, dx | |
mov [state32], ecx | |
popad | |
ret | |
state8 db 0 | |
state16 dw 0 | |
state32 dd 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment