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 


Random number is Lua.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Mar 25, 2016 3:33 pm    Post subject: Random number is Lua. Reply with quote

Code:

math.randomseed(os.time())
x = math.random(0,10)
y = math.random(0,10)


Is it possible that x equals y by using this code? If so, how do I make sure that y does not equal x while getting a random number from 0 -10?

Thanks in advance.

Will the following work?
Edit:
Code:

math.randomseed(os.time())
x = math.random(0,10)
y = math.random(0,10)
if y == x then
    while y == x do
       y = math.random(0,10)
    end
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4709

PostPosted: Fri Mar 25, 2016 3:48 pm    Post subject: Reply with quote

Yes, it is possible.
Code:
math.randomseed(os.time())
local x = math.random(0,10)
local y = math.random(0,10)
while x == y do y = math.random(0,10) end

Now, x will never equal y after that line of code.
This might not be the best way. If this were a true random number generator, I suppose it's possible for the program to be stuck there forever; however, I wouldn't worry about it that much.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Mar 25, 2016 4:41 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Yes, it is possible.
Code:
math.randomseed(os.time())
local x = math.random(0,10)
local y = math.random(0,10)
while x == y do y = math.random(0,10) end

Now, x will never equal y after that line of code.
This might not be the best way. If this were a true random number generator, I suppose it's possible for the program to be stuck there forever; however, I wouldn't worry about it that much.


Got it, thank you for the reply. Very Happy
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 programming 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