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

a

An integer representing the inclusive lower bound of the range.

b

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

start

A float or integer representing the lower bound of the range.

end

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

start

Optional. An integer representing the inclusive starting value of the range. Default is 0.

stop

An integer representing the exclusive ending value of the range.

step

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

n

An integer representing the number of random bits (0 <= n <= 32).

# Example coming soon

Selection#

choice#

choice chooses and returns one item at random from a sequence.

Usage:
random.choice(sequence)

Parameter

Description

sequence

A non-empty sequence (list, tuple, or other indexable object) from which a random element is selected.

# Example coming soon