Two functions are required:
(1) math.randomseed(N): Receive an integer N as a random sequence seed
(2) math.random([n, [m]]): This function has three uses, respectively, without parameters, at this time, a random floating point number between (0, 1) is generated; there is a parameter n, which generates 1 Integer between n and n; has 2 parameters n and m, and generates a random integer between n and m.
The most common method is
math.randomseed(os.time())
for i=0, 10 do local n = math.random(10) print(n) N in end
math.randseed(N) also changes, so that the random sequence generated each time can be guaranteed to be non-repeated (with a small probability).