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 


[Auto Assemble] Generate random number from 0 to K

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Peeszdyetc
How do I cheat?
Reputation: 0

Joined: 27 Jun 2023
Posts: 4

PostPosted: Sat Jul 01, 2023 2:56 pm    Post subject: [Auto Assemble] Generate random number from 0 to K Reply with quote

Posting it here because google forward me to this forum firstly but I'm not found a final solution here. Can't even post a link to source because of forum restrictions. You can find the solution on fearlesssrevolution forums by exact same thread name as this.
Source: fearlessrevolution*com/viewtopic.php?f=23&t=25089&p=302778#p302778
Code:
[Enable]
alloc(start, 2048)
label(originalcode)
label(exit)
label(randomValue)         
label(returnhere)

start:
pushad
mov     eax, 0x2000001     
cpuid
rdtsc
and     eax, K             
mov     [randomValue], eax 
popad

originalcode:
mov     eax, [randomValue] 
mov     ebp,eax
mov     edi, [...]

exit:
jmp returnhere

randomValue:
dd      0

...:
jmp     start
nop     3
returnhere:


[Disable]
dealloc(start)
...
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3326

PostPosted: Sat Jul 01, 2023 7:28 pm    Post subject: Reply with quote

rdtsc reads a timestamp counter - it's the opposite of random, it's counting up until processor reset.
I'd try the rdrand instruction instead.
Code:
rdrand ax
rdrand eax
rdrand rax

All of these are valid. You can use EBX, ECX, or any other register.
Check the Intel Developer's Manual, some conditions apply.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Sat Jul 01, 2023 11:59 pm    Post subject: Reply with quote

value & k ?

that means the K can only be 1,3,15,31, etc...

lets say that K is 8, then the only 2 values this random value generator returns is either 0 or 8

i'd do:
Code:

call rand  //or rdtsc if you prefer
push rdx
div dword ptr [Kvalue] //divide the value in eax by kvalue. The result will be in eax and edx, where eax contains the number of times it can be divided, and edx the result left (which goes from 0 to K-1)
mov [randomValue],edx //put the remainder in randomValue
pop rdx

_________________
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
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