Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the random generation of big lottery numbers by Python

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to achieve random generation of big lotto numbers by Python". In daily operation, I believe many people have doubts about how to achieve random generation of big lotto numbers by Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve random generation of big lotto numbers by Python". Next, please follow the editor to study!

1. Random bet

The sports lottery contains seven numbers, including five red balls and two basketballs.

Among them

The red ball is to choose five different numbers from 1 to 35.

The blue ball is to choose two different numbers from 1 to 12.

The code for randomly generating a note number using Python is as follows:

Def gene_dlt (number): "" Random Multi-bet Lotto: param number:: return: "" result = [] for index in range (number): # generate five red balls red = random.sample ([i for i in range (1,36)], 5) # generate two blue balls blue = random.sample ([i for i in range (1,13)] 2) # sort red.sort () blue.sort () # data processing red = nums_pre (red) blue = nums_pre (blue) result.append (''.join (red) + "+" +' .join (blue)) return'\ n'.join (result)

It should be noted that in order to facilitate the later judgment of whether to win the lottery, a data preprocessing is carried out, and the numbers less than 10 are preceded by 0.

Def nums_pre (nums): "" purchase digital preprocessing, if single digit Add 0: param nums:: return: "if nums: if isinstance (nums, list) or isinstance (nums) Tuple): return ['0 {} '.format (int (item)) if int (item) < 10 else str (int (item)) for item in nums] else: return' 0 {} '.format (int (nums)) if int (nums) < 10 else str (int (nums) else: return''2. Red ball fixed or blue ball fixed

Many lottery buyers think that the winning number is irregular, so they will choose to make a fixed purchase according to their lucky numbers.

Red ball fixed

When the red ball is fixed, we only need to generate the blue ball randomly, then sort it, preprocess the data, and finally form a note number.

Def gene_blue_random_dlt (red, number): red ball fixed Basketball random: param red: red ball: param number: random bet: return: "result = [] for index in range (number): # generate two blue balls blue = random.sample ([i for i in range (1,13)]] 2) # sort red.sort () blue.sort () # data processing red = nums_pre (red) blue = nums_pre (blue) result.append (''.join (red) + "+" +' .join (blue)) return'\ n'.join (result) Blue Ball is fixed

When the blue ball is fixed, we only need to randomly generate five different numbers from 1 to 35.

Def gene_red_random_dlt (blue, number): "" five red balls are random. 2 Basketball fixed: param blue: blue Ball list: param number: random Note: return: "" result = [] for index in range (number): # generate 5 red balls red = random.sample ([i for i in range (1,36)]] 5) # sort red.sort () blue.sort () # data processing red = nums_pre (red) blue = nums_pre (blue) result.append (''.join (red) + "+" +' .join (blue)) return'\ n'.join (result) 3. Climb the winning number

The opening time of the sports lottery is usually between 9 p.m. and 10:00, and brother fried egg suggests that we crawl at 10:30 in the evening to ensure the stability and accuracy of the crawling data.

Destination address:

AHR0cHM6Ly9rYWlqaWFuZy41MDAuY29tL3N0YXRpYy9pbmZvL2thaWppYW5nL3htbC9kbHQvbGlzdC54bWw=

The website shows the winning numbers of each big lottery through XML data. We only need to use regular expressions to match all the winning numbers and take the most recent number.

Import reimport requestsclass DLT (object): def _ _ init__ (self): # get (official account: fried eggs for money) self.url ='* * 'self.headers = {' User-Agent': 'Mozilla/5.0 (Macintosh) Intel Mac OS X 10 / 11 / 2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'} def get_last_dlt_lucky (self): # initiate a request reponse = requests.get (url=self.url, headers=self.headers) # regular rule pattern = re.compile (r'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report