mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 01:16:28 +08:00
commit
5b99d8b4f3
1 changed files with 1 additions and 1 deletions
|
@ -137,7 +137,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||||
""" 随机访问元素 """
|
""" 随机访问元素 """
|
||||||
def randomAccess(nums):
|
def randomAccess(nums):
|
||||||
# 在区间 [0, len(nums)) 中随机抽取一个数字
|
# 在区间 [0, len(nums)) 中随机抽取一个数字
|
||||||
random_index = random.randint(0, len(nums))
|
random_index = random.randint(0, len(nums)-1)
|
||||||
# 获取并返回随机元素
|
# 获取并返回随机元素
|
||||||
random_num = nums[random_index]
|
random_num = nums[random_index]
|
||||||
return random_num
|
return random_num
|
||||||
|
|
Loading…
Reference in a new issue