The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Shirakami on July 22, 2017, 11:57:10 AM

Title: How can I use Random numbers?
Post by: Shirakami on July 22, 2017, 11:57:10 AM
Hello. Help me!

I was trying to use a random number in the script, but I could not.


local i = rand()
local i = random()
local i = math.rand()
local i = math_rand()


How can I use random numbers in a script?
Title: Re: How can I use Random numbers?
Post by: Dwachs on July 22, 2017, 02:28:42 PM
I added the missing functionality in r8272.

srand(time()) // initialize random number generator
local bal = rand() // get random number

It uses the functions srand and rand from the standard C libraries.
Title: Re: How can I use Random numbers?
Post by: Shirakami on July 22, 2017, 03:17:53 PM
Quote from: Dwachs on July 22, 2017, 02:28:42 PM
I added the missing functionality in r8272.

Thank you for your prompt response!  ;D