update python randomAccess
random.randomint(start, stop) 返回 数字的范围是 [start, stop] 是一个闭区间, 如果用len(nums) 有可能会索引超出范围
This commit is contained in:
parent
004f570512
commit
dab16ee53a
@ -137,7 +137,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||
""" 随机访问元素 """
|
||||
def randomAccess(nums):
|
||||
# 在区间 [0, len(nums)) 中随机抽取一个数字
|
||||
random_index = random.randint(0, len(nums))
|
||||
random_index = random.randint(0, len(nums)-1)
|
||||
# 获取并返回随机元素
|
||||
random_num = nums[random_index]
|
||||
return random_num
|
||||
|
Loading…
x
Reference in New Issue
Block a user