随机的#
介绍#
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#
randint
returns a random integer between two values (inclusive), where both values are integers.
Usage:
random.randint(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)
范围 |
描述 |
---|---|
|
表示范围下限的浮点数或整数。 |
|
表示范围上限的浮点数或整数。 |
# 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)
范围 |
描述 |
---|---|
|
可选。一个整数,表示范围的起始值(含)。默认值为 0。 |
|
表示范围的唯一结束值的整数。 |
|
可选。一个整数,表示范围内每个数字之间的差值。默认值为 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)
范围 |
描述 |
---|---|
|
An integer representing the number of random bits |
# Example coming soon
选择#
choice#
choice
returns a random element from a non-empty list or sequence.
Usage:
random.choice(sequence)
范围 |
描述 |
---|---|
|
从中选择随机元素的非空序列(列表、元组或其他可索引对象)。 |
# Example coming soon