随机的#

介绍#

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.

以下是可用方法的列表:

  • randint – 返回两个值之间的随机整数(含)。

  • uniform – 返回两个值之间的随机浮点数。

  • randrange – 返回一个范围内的随机整数,并带有可选步骤。

  • random – 返回 0.0(含)到 1.0(不含)之间的随机浮点数。

  • getrandbits – 返回具有指定数量随机位的整数。

  • 选择 – 从非空列表或序列中返回一个随机元素。

数字生成器#

randint#

randint returns a random integer between two values (inclusive), where both values are integers.

Usage:
random.randint(a, b)

范围

描述

a

表示范围的包含下限的整数。

b

表示范围上限的整数。

# Example coming soon

uniform#

uniform returns a random float between two values, where both values are floats or integers.

Usage:
urandom.uniform(start, end)

范围

描述

start

表示范围下限的浮点数或整数。

end

表示范围上限的浮点数或整数。

# 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)

范围

描述

start

可选。一个整数,表示范围的起始值(含)。默认值为 0。

stop

表示范围的唯一结束值的整数。

step

可选。一个整数,表示范围内每个数字之间的差值。默认值为 1。

# Example coming soon

random#

random returns a random float between 0.0 (inclusive) and 1.0 (exclusive).

Usage:
random.random()

范围

描述

该方法没有参数。

# 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)

范围

描述

n

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

# Example coming soon

选择#

choice#

choice returns a random element from a non-empty list or sequence.

Usage:
random.choice(sequence)

范围

描述

sequence

从中选择随机元素的非空序列(列表、元组或其他可索引对象)。

# Example coming soon