Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Randomness

Lua provides a pseudo-random number generator. This means a program will generate the same random number on every run, unless the random number is seeded. The random function can be called with the following arguments:

  • math.random(): with no arguments generates a real number between 0 and 1
  • math.random(max): generates integer numbers between 1 and max
  • math.random(min, max): generates integer numbers between min and max

When generating a random number, min and max must be integer values. If the numbers provided are not integers, Lua will cast the numbers to be integers by discarding the decimal part.

To get a random sequence of numbers each time an application is run, the random number generator must be seeded. Seeding the random ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content