Jump to content

Random?


Hugos

Recommended Posts

Posted

I created the function math.random (10, 20), but I get 10 all the time. Help please! How do I always generate different numbers?

Говорю на русском. Sorry for bad english.
 

  • Moderators
Posted (edited)
20 minutes ago, Hugos said:

I created the function math.random (10, 20), but I get 10 all the time.

https://docs.coronalabs.com/api/library/math/randomseed.html

 

os.time() can be replaced with getTickCount()

Edited by IIYAMA

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted (edited)
42 minutes ago, IIYAMA said:

https://docs.coronalabs.com/api/library/math/randomseed.html

 

os.time() can be replaced with getTickCount()

Did not understand a little. Can I see an example of a function that generates a random number in a range?

P.S: I use Lua random.match - https://www.gammon.com.au/scripts/doc.php?Lua=math.random (not api)

Edited by Hugos

Говорю на русском. Sorry for bad english.
 

  • Moderators
Posted
1 hour ago, Hugos said:

Did not understand a little. Can I see an example of a function that generates a random number in a range?

It helps with randomization. And no I wouldn't mention it, if it isn't available in MTA.

 

This is all: Run on top of your script.

math.randomseed(getTickCount())

-- or

math.randomseed(getTickCount() * getTickCount())

 

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...