update python randomAccess

random.randomint(start, stop) 返回  数字的范围是 [start, stop] 是一个闭区间, 如果用len(nums) 有可能会索引超出范围
pull/264/head
weibk 2 years ago committed by GitHub
parent 004f570512
commit dab16ee53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save