Skip to main content

Function randi() in expressions

randi() - is a function that allows you to generate a random integer in a given range.

The method of presenting information in this manual assumes that you have already familiarized yourself with the documents indicated by the links and, in general, understand the principles of the described functionality.

 

❖ Required functionality

 

Additional variables.
To connect, go in your bot:
☞ 🔐Admin | 🧩Extensions | 📂Variables

Macros and expressions in buttons.
To connect, go in your bot:
☞ 🔐Admin | 🧩Extensions | 📂Buttons

Conditions.
To connect, go in your bot:
☞ 🔐Admin | 🧩Extensions | 📂Buttons

Package of additional "Tokens of Functions".
To connect, go in your bot:
☞ 🔐Admin | 🧩Extensions | 📂Actions

IMPORTANT: The purchase of functionality for the bot is available only to the Creator (owner) of the bot. Admins CANNOT buy functionality!

Some calculations need to use a random number generator. The examples below will help you with this.

 

Random number from -100 to +100

Use when you need to randomly add or subtract a number. If you multiply any number by this expression, it will randomly determine its sign (Plus or Minus), which will allow you, for example, to randomly add or subtract a value in a variable (or a bonus, for example).

To determine (Plus / Minus) sign, let's use a rands() function  from the Expressions Manual. The function randi() will generate a random number between 1 and 100, and multiplying it by the function value of rands() will make the result negative or positive. Thus, a random number from -100 to -1 and from +1 to +100 (not zero) will be returned.

The final expression will look like this:

{randi(1, 100) * rands()}