Random#

Introduction#

Random provides access to Python’s random module, which is available by default in VEXcode GO. 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.

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 between two values (inclusive), where both values are integers.

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 two values, where both values are floats or integers.

Usage:
urandom.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 a range with an optional step, where both the start and stop values are integers.

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 between 0.0 (inclusive) and 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, where the number of bits is an integer between 0 and 32.

Usage:
random.getrandbits(n)

Parameter

Description

n

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

# Example coming soon

Selection#

choice#

choice returns a random element from a non-empty list or 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