Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


RANDOMIZE A VALUE

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
djdoom32
Newbie cheater
Reputation: 0

Joined: 11 Mar 2012
Posts: 19
Location: germany

PostPosted: Sat Dec 26, 2015 3:52 pm    Post subject: RANDOMIZE A VALUE Reply with quote

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
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Sat Dec 26, 2015 4:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25830
Location: The netherlands

PostPosted: Sat Dec 26, 2015 4:49 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
djdoom32
Newbie cheater
Reputation: 0

Joined: 11 Mar 2012
Posts: 19
Location: germany

PostPosted: Sat Dec 26, 2015 5:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Sat Dec 26, 2015 9:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
djdoom32
Newbie cheater
Reputation: 0

Joined: 11 Mar 2012
Posts: 19
Location: germany

PostPosted: Sun Dec 27, 2015 6:57 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites