| View previous topic :: View next topic |
| Author |
Message |
djdoom32 Newbie cheater
Reputation: 0
Joined: 11 Mar 2012 Posts: 19 Location: germany
|
Posted: Sat Dec 26, 2015 3:52 pm Post subject: RANDOMIZE A VALUE |
|
|
hi all
Need some help
i want to randomize a value between 100k and 350 k here:
mov ebx,055730
it allways generate 350k now. how can i randomize it?
|
|
| Back to top |
|
 |
Gniarf Grandmaster Cheater Supreme
Reputation: 43
Joined: 12 Mar 2012 Posts: 1285
|
Posted: Sat Dec 26, 2015 4:43 pm Post subject: |
|
|
Amongst others, here's a crude method: | Code: | push eax //save eax anb edx
push edx
rdtsc //read CPU clock cycles
and eax, 3FFFF //reduce range to 0-262 143
add eax,#100000 //shift range to 100 000 - 362 143
mov ebx,eax //put result in ebx
pop edx //restore eax and edx
pop eax | This will output a random value between 100k and 362k. If you prefer a value between 100k and 231k, put 2FFFF instead of 3FFFF.
_________________
DO NOT PM me if you want help on making/fixing/using a hack. |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25830 Location: The netherlands
|
Posted: Sat Dec 26, 2015 4:49 pm Post subject: |
|
|
the rand function returns a value between 0 and 32767
you wish a value between 100000 and 350000
so, we start at 100000 and then add a value of 0 to 250000 to it.
to get a value between 0 and 250000 from a value of 0 to 32767 we multiple the resulting value with: 250000/32767=7 (or 8 if you don't mind going over 350k a little)
so:
| Code: |
push eax //save some of the changed registers
push edx
push ecx
call rand
//eax now contains a value between 0 and 32767
mov ecx,7
mul ecx //multiplies eax with the value in ecx (7) and store it into eax:edx
mov ebx, eax
add ebx,#100000
//restore the changed registers
pop ecx
pop edx
pop eax
//ebx now contains a value of between 100000 and 329369
|
or check gniarf's answer
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
djdoom32 Newbie cheater
Reputation: 0
Joined: 11 Mar 2012 Posts: 19 Location: germany
|
Posted: Sat Dec 26, 2015 5:23 pm Post subject: |
|
|
| Dark Byte wrote: | the rand function returns a value between 0 and 32767
you wish a value between 100000 and 350000
so, we start at 100000 and then add a value of 0 to 250000 to it.
to get a value between 0 and 250000 from a value of 0 to 32767 we multiple the resulting value with: 250000/32767=7 (or 8 if you don't mind going over 350k a little)
so:
| Code: |
push eax //save some of the changed registers
push edx
push ecx
call rand
//eax now contains a value between 0 and 32767
mov ecx,7
mul ecx //multiplies eax with the value in ecx (7) and store it into eax:edx
mov ebx, eax
add ebx,#100000
//restore the changed registers
pop ecx
pop edx
pop eax
//ebx now contains a value of between 100000 and 329369
|
or check gniarf's answer |
gniarf s code works great but i want to use yours. its near to 350k.
Thx u both.
|
|
| Back to top |
|
 |
Gniarf Grandmaster Cheater Supreme
Reputation: 43
Joined: 12 Mar 2012 Posts: 1285
|
Posted: Sat Dec 26, 2015 9:36 pm Post subject: |
|
|
Thinking again about it there is a simple way to get the exact desired range: | Code: | push eax //save eax and edx
push edx
rdtsc //read CPU clock cycles
xor edx,edx //prevents integer overflow eexception when dividing
mov ebx,#250001
div ebx //divide clock cycles by 250k+1, so now edx is the remainder, in the 0-250k range
add edx,#100000 //now edx is in the 100k-350k range
mov ebx,edx //put result in ebx
pop edx //restore eax and edx
pop eax |
_________________
DO NOT PM me if you want help on making/fixing/using a hack. |
|
| Back to top |
|
 |
djdoom32 Newbie cheater
Reputation: 0
Joined: 11 Mar 2012 Posts: 19 Location: germany
|
Posted: Sun Dec 27, 2015 6:57 am Post subject: |
|
|
| Gniarf wrote: | Thinking again about it there is a simple way to get the exact desired range: | Code: | push eax //save eax and edx
push edx
rdtsc //read CPU clock cycles
xor edx,edx //prevents integer overflow eexception when dividing
mov ebx,#250001
div ebx //divide clock cycles by 250k+1, so now edx is the remainder, in the 0-250k range
add edx,#100000 //now edx is in the 100k-350k range
mov ebx,edx //put result in ebx
pop edx //restore eax and edx
pop eax |
|
thx amazing. I owe you something.
|
|
| Back to top |
|
 |
|