News:

SimuTranslator
Make Simutrans speak your language.

How can I use Random numbers?

Started by Shirakami, July 22, 2017, 11:57:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Shirakami

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?

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

Shirakami

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