Posted: Sun Sep 29, 2013 2:23 pm Post subject: Very basic random numbers in ASM?
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.
Joined: 25 Jun 2011 Posts: 59 Location: CEDisasmView
Posted: Mon Sep 30, 2013 2:56 am Post subject:
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.
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?
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