Gets a random integer within the range of the specified minimum and maximum numbers.
This block can be used in place of any number. It works well for generating a random integer. For example, it can be used to randomize a sprite’s property or location.
Examples
Example 1
Make a sprite of a random size.
Example 2
The results of the race will change every time the project is run because the car and motorcycle will move a random number of pixels north each time the up arrow is pressed.
Syntax
math_random_int
Parameters
Name | Type | Required? | Description |
---|---|---|---|
number (max) | The maximum number generated | ||
number (min) | The minimum number generated |
Tips
- Negative values for min or max are allowed.
- If you accidentally make min larger than max it will still return a random number in the range.
Found a bug in the documentation? Let us know at support@code.org.