def split_number_into_n_parts(total, n):
# 确保total大于0且可以被分成n个非负数
if total <= 0 or n <= 0:
raise ValueError("Total must be positive and n must be a positive integer.")
# 生成n-1个随机数并将它们累加
parts = [random.uniform(0, total) for _ in range(n - 1)]
sum_of_generated_parts = sum(parts)
# 为了避免浮点运算误差,确保最后一部分直接计算以保证总和准确
remaining = total - sum_of_generated_parts
parts.append(remaining)
# 如果需要确保都是正数且总和完全精确等于total,可以考虑调整生成策略或后续处理
return parts
def valley_sort(nums):
nums = sorted(nums)
mid = len(nums) // 2
# 如果列表长度是奇数,包含中间值两次;如果是偶数,则正常处理
valley_list = nums[mid::-1] + nums[mid + 1:] + nums[mid:mid + 1] if len(nums) % 2 == 1 else nums[mid::-1] + nums[
mid:]
return valley_list
def pass_slider():
slider_btn = page.ele('#nc_1_n1z')
slider_btn_width = slider_btn.size[0]
slider_width = page.ele('.nc-lang-cnt').size[0]
ac = Actions(page)
ac.hold(slider_btn)
steps = valley_sort(split_number_into_n_parts(slider_width - slider_btn_width, 5))
for step in steps:
ac.move(step, 0)
ac.wait(random.uniform(0.9, 1.1))
page.wait(2)
pass_slider()
05-27
887
05-08
1万+
05-27
899
02-07
192
08-06
580