flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Random number macro |
Author |
|
decard 03 Oct 2004, 18:34
try this:
Code: random_seed = ((random_seed*214013+2531011) shr 16) and 0xffffffff you can use %t as an initial value of random_seed |
|||
03 Oct 2004, 18:34 |
|
omega_red 03 Oct 2004, 19:13
Thanks, that's working.
|
|||
03 Oct 2004, 19:13 |
|
Matrix 09 Nov 2004, 15:07
i have made my latest randomz3 routine a macro version
Code: __lasttimevar=0 __random_seed = %t __range=$ffffffff macro db_4random_bytes { ;randomz3: ; Z3 ecx=range transparent __timevar=%t __random_seed=(__random_seed+__timevar)and 0xffffffff __al=(__timevar and $ff) xor ((__timevar shr 8) and $ff) __ch_1=(__range shr 8) and $ff ;ror ch,4 __ch_tmp1=(__ch_1 shr 4) and $f __ch_tmp2=(__ch_1 and $f) shl 4 __ch=__ch_tmp1 or __ch_tmp2 ;xor bl,ch __bl_1=__random_seed and $ff __bl=__bl_1 xor __ch_1 cl_and_f=__range and $f __bx_1=__random_seed and $ffff ;rol bx,cl __bx_tmp1=(__bx_1 shl cl_and_f) __bx_tmp2=(__bx_tmp1 shr 16) __bx_tmp1=__bx_tmp1 and $ffff __bx=__bx_tmp1 or __bx_tmp2 ;btc bx,cx __bx=__bx xor (1 shl cl_and_f) __bx=__bx xor ((__timevar and $ff)xor((__timevar shr 16) and $ff)) ;mov cl,al xor cl,ah __al=(__timevar and $ff) xor ((__timevar shr 8) and $ff) ;ror ch,4 __ch_tmp1=(__ch_1 shr 4) and $f __ch_tmp2=(__ch_1 and $f) shl 4 __ch=__ch_tmp1 or __ch_tmp2 ;xor bl,ch __bl=__bl_1 xor __ch_1 ;ror bx,cl __bx_tmp1=__bx_1 shl 16 __bx_tmp2=(__bx_tmp1 shr cl_and_f) and $ffff __bx_tmp1=__bx_tmp2 shr 16 __bx=__bx_tmp1 or __bx_tmp2 ;btc bx,cx __bx=__bx xor (1 shl cl_and_f) __bx=__bx xor ((__timevar and $ff)xor((__timevar shr 16) and $ff)) __cl=__bx and $ff repeat __cl ;rol eax,cl __timevar_tmp1=(__timevar shl __cl) and $ffffffff __timevar_tmp2=(__timevar shr (32-__cl)) and $ffffffff __timevar=__timevar_tmp1 or __timevar_tmp2 __cl=__cl and $f ;btc ax,cx __timevar=__timevar xor (1 shl __cl) end repeat __cl=(__bx shr 8) and $ff repeat __cl ;ror eax,cl __timevar_tmp1=(__timevar shl (32-__cl)) and $ffffffff __timevar_tmp2=(__timevar shr __cl) __timevar=__timevar_tmp1 or __timevar_tmp2 __cl=__cl and $f ;btc ax,cx __timevar=__timevar xor (1 shl __cl) end repeat __timevar=__timevar mod __range dd __timevar and $ffffffff } db_4random_bytes db_4random_bytes db_4random_bytes |
|||
09 Nov 2004, 15:07 |
|
Matrix 09 Nov 2004, 16:09
i have made it cleaned up, and i can't mke it work on multiple bytes, cause %t is not rdtsc, ccan't get current timstamp while compiling.
Code: __lasttimevar=0 __random_seed = %t ;__range=$ffffffff __range=1 macro db_4random_bytes ;randomz3 __range=range __random_seed= random seed { __timevar=%t __random_seed=__random_seed + %t and 0xffffffff __al=(__timevar and $ff) xor ((__timevar shr 8) and $ff) __ch_1=(__range shr 8) and $ff ;ror ch,4 __ch_tmp1=(__ch_1 shr 4) and $f __ch_tmp2=(__ch_1 and $f) shl 4 __ch=__ch_tmp1 or __ch_tmp2 ;xor bl,ch __bl_1=__random_seed and $ff __bl=__bl_1 xor __ch_1 cl_and_f=__range and $f __bx_1=__random_seed and $ffff ;rol bx,cl __bx_tmp1=(__bx_1 shl cl_and_f) __bx_tmp2=(__bx_tmp1 shr 16) __bx_tmp1=__bx_tmp1 and $ffff __bx=__bx_tmp1 or __bx_tmp2 ;btc bx,cx __bx=__bx xor (1 shl cl_and_f) __bx=__bx xor ((__timevar and $ff)xor((__timevar shr 16) and $ff)) ;mov cl,al xor cl,ah __al=(__timevar and $ff) xor ((__timevar shr 8) and $ff) ;ror ch,4 __ch_tmp1=(__ch_1 shr 4) and $f __ch_tmp2=(__ch_1 and $f) shl 4 __ch=__ch_tmp1 or __ch_tmp2 ;xor bl,ch __bl=__bl_1 xor __ch_1 ;ror bx,cl __bx_tmp1=__bx_1 shl 16 __bx_tmp2=(__bx_tmp1 shr cl_and_f) and $ffff __bx_tmp1=__bx_tmp2 shr 16 __bx=__bx_tmp1 or __bx_tmp2 ;btc bx,cx __bx=__bx xor (1 shl cl_and_f) __bx=__bx xor ((__timevar and $ff)xor((__timevar shr 16) and $ff)) __cl=__bx and $ff repeat __cl ;rol eax,cl __timevar_tmp1=(__timevar shl __cl) and $ffffffff __timevar_tmp2=(__timevar shr (32-__cl)) and $ffffffff __timevar=__timevar_tmp1 or __timevar_tmp2 __cl=__cl and $f ;btc ax,cx __timevar=__timevar xor (1 shl __cl) end repeat __cl=(__bx shr 8) and $ff repeat __cl ;ror eax,cl __timevar_tmp1=(__timevar shl (32-__cl)) and $ffffffff __timevar_tmp2=(__timevar shr __cl) __timevar=__timevar_tmp1 or __timevar_tmp2 __cl=__cl and $f ;btc ax,cx __timevar=__timevar xor (1 shl __cl) end repeat __timevar=__timevar mod __range dd __timevar and $ffffffff } repeat 120 db_4random_bytes end repeat |
|||
09 Nov 2004, 16:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.