ErikF Posted January 22 Share Posted January 22 Hi, I have a script in which math.random generates a number and I don't want the number I generate to be decodable by the user. Therefore, if someone has been in a similar situation, could you explain how exactly this function works if I don't use the math.randomseed() function? Perhaps someone knows what seed is pulled in by default that is used to generate the number? Thanks in advance for any help! Link to comment
Tekken Posted January 26 Share Posted January 26 Hi, think of math.randomseed() like the starting poit of your randomness, the seed, in order to have unpredictable random numbers you have to provide a integer seed to this function and from now on in your script the random numbers will be generated from this seed, like: This will give you the same results every single time the code is generated for i = 1, 10 do print(math.random()); end While this will change every single time due to getRealTime().timestamp never returning the same number. math.randomseed(getRealTime().timestamp); for i = 1, 10 do print(math.random()); end Link to comment
FernandoMTA Posted January 26 Share Posted January 26 shorter version: math.randomseed(os.time()) Link to comment
Tekken Posted January 27 Share Posted January 27 On 26/01/2024 at 12:30, FernandoMTA said: shorter version: math.randomseed(os.time()) Not sure os functions work in MTA, but I may be wrong Link to comment
FernandoMTA Posted January 29 Share Posted January 29 On 27/01/2024 at 12:37, Tekken said: Not sure os functions work in MTA, but I may be wrong The ones that haven't been blocked do work! os.date can be useful to format dates for example Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now