G1R:MP Forum Alpha
Log in Join
Gothic 1 Remake Multiplayer

The Colony Forum

News, support, development discussions, server communities, and stories from beyond the Barrier.

Colony discussion

Random Number

Started by Xardas0327 in Suggestions

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
09-13-2026, 05:45 PM
#2
Lua 5.1 already provides a built-in pseudo-random number generator through the `math` library.

Available functions:

```lua
math.random()
```

Returns a pseudo-random floating-point number between `0` and `1`.

```lua
math.random(max)
```

Returns a pseudo-random integer between `1` and `max`.

Example:

```lua
local number = math.random(100)
print(number) -- 1-100
```

You can also specify both the minimum and maximum value:

```lua
math.random(min, max)
```

Example:

```lua
local number = math.random(10, 50)
print(number) -- 10-50
```

It's also recommended to initialize the random seed once when the script starts:

```lua
math.randomseed(os.time())
```

Full example:

```lua
math.randomseed(os.time())

local randomNumber = math.random(1, 100)

print("Random number: " .. randomNumber)
```

So unless there is a specific reason to implement a custom random number generator, Lua 5.1's built-in `math.random()` should be enough for most gameplay/script purposes.
Forum Jump: