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 


Very basic random numbers in ASM?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
pox911
Grandmaster Cheater
Reputation: 28

Joined: 29 Nov 2008
Posts: 918

PostPosted: Sun Sep 29, 2013 2:23 pm    Post subject: Very basic random numbers in ASM? Reply with quote

I've been googling but i havent found something that i fully understand. Basicly i just want a simple random number generator between two values. For how much the function is called it makes more sense to do it this way than to use lua. I'm probably over looking something really simple again.
Back to top
View user's profile Send private message
eax.qbyte
Advanced Cheater
Reputation: 3

Joined: 25 Jun 2011
Posts: 59
Location: CEDisasmView

PostPosted: Mon Sep 30, 2013 2:56 am    Post subject: Reply with quote

If you need only and only one number that changes every time, no matter the max value and min value, and doesn't have to be filling the edges or ....
Then a seed generator is enough for that purpose. You can easily seed a unpredictable number using time related functions. One of them is getTickCount. After calling that function register EAX contains that seed value.

rand function from C Compiler library creates a random number in EAX register too. But the series of random numbers created by this function is always the same.
Use srand function to randomize the sequence of numbers created by rand function. srand Needs a integer number as seed for input parameter. Same seeds for srand will cause rand function to generate same series of numbers.
So use time related functions to generate random seeds.

I guess this should be similar to the code to generate some random numbers:
Code:
//Only once in a module {
  call getTickCount
  push eax
  call srand
//}

// as much as required
  call rand
// a new random number in eax
 call rand
// a new random number in eax
....
// div (max-min)
// add edx,min
// now min < edx < max

_________________
My special thanx to Cheat Engine and its developers. It helps me do the hard and boring but valuable process of understanding the code, easily and with fun.
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
pox911
Grandmaster Cheater
Reputation: 28

Joined: 29 Nov 2008
Posts: 918

PostPosted: Mon Sep 30, 2013 2:23 pm    Post subject: Reply with quote

thanks. Another minor question to go with this. Is there a proper way of writing a single byte to memory?

I tried using AL and byte ptr for stuff but it doesnt seem to actually move so i must be over looking something
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Mon Sep 30, 2013 2:55 pm    Post subject: Reply with quote

mov byte ptr [YourAddress],0xYourByte

that simple
Back to top
View user's profile Send private message
pox911
Grandmaster Cheater
Reputation: 28

Joined: 29 Nov 2008
Posts: 918

PostPosted: Mon Sep 30, 2013 5:27 pm    Post subject: Reply with quote

im wanting the byte to be the result of the random number. From my understanding i would have to store it in a single byte register like AL and then use the move byte ptr [my adress], al. Am i wrong in that thinking?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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