Random#
Introduction#
Random provides access to Python’s random
module, which is available by default in VEXcode AIR. These methods let you generate random numbers, floats, and values from lists or ranges—useful for adding unpredictability to games, behaviors, and autonomous decision-making. To begin using these functions, add import random
at the top of the project.
Below is a list of available methods:
randint – Returns a random integer between two values (inclusive).
uniform – Returns a random float between two values.
randrange – Returns a random integer from a range with an optional step.
random – Returns a random float between 0.0 (inclusive) and 1.0 (exclusive).
getrandbits – Returns an integer with a specified number of random bits.
choice – Returns a random element from a non-empty list or sequence.
Number Generators#
randint#
randint
returns a random integer in the range [a, b]
.
Usage:
random.randint(a, b)
Parameter |
Description |
---|---|
|
An integer representing the inclusive lower bound of the range. |
|
An integer representing the inclusive upper bound of the range. |
# Example coming soon
uniform#
uniform
returns a random float between start
and end
.
Usage:
random.uniform(start, end)
Parameter |
Description |
---|---|
|
A float or integer representing the lower bound of the range. |
|
A float or integer representing the upper bound of the range. |
# Example coming soon
randrange#
randrange
returns a random integer from the specified range.
Usage:
random.randrange(start, stop, step)
Parameter |
Description |
---|---|
|
Optional. An integer representing the inclusive starting value of the range. Default is 0. |
|
An integer representing the exclusive ending value of the range. |
|
Optional. An integer representing the difference between each number in the range. Default is 1. |
# Example coming soon
random#
random
returns a random float in the range 0.0
(inclusive) to 1.0
(exclusive).
Usage:
random.random()
Parameter |
Description |
---|---|
This method has no parameters. |
# Example coming soon
getrandbits#
getrandbits
returns an integer with a specified number of random bits.
Usage:
random.getrandbits(n)
Parameter |
Description |
---|---|
|
An integer representing the number of random bits |
# Example coming soon
Selection#
choice#
choice
chooses and returns one item at random from a sequence.
Usage:
random.choice(sequence)
Parameter |
Description |
---|---|
|
A non-empty sequence (list, tuple, or other indexable object) from which a random element is selected. |
# Example coming soon