In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people don't understand the knowledge points of this article "How Python realizes random generation of two-color ball numbers", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "How Python realizes random generation of two-color ball numbers".
1. random one bet
A note also contains 7 numbers, including 6 red balls and 1 basketball.
wherein
The red ball is 6 different numbers from 1 to 33.
A basketball is a number from 1 to 16.
Use Python to randomly generate a note two-color ball number, part of the code is as follows:
def gene_ssq(number): """ Randomly generate several notes of bicolor ball (6+1) :param number: :return: """ result = [] for item in range(number): reds = [] 6 red balls while len(reds) < 6: #Take a random number from 1-33 temp_red_num = random.randint(1, 33) if temp_red_num not in reds: reds.append(temp_red_num) #Blue ball blue = random.randint(1, 16) #Red ball sort reds.sort() #Data preprocessing reds = nums_pre(reds) blue = nums_pre([blue])[0] result.append(' '.join(reds) + " + " + blue) return '\n'.join(result)
It should be noted that, in order to facilitate the later judgment of whether to win the prize, here the red ball list for a data preprocessing, the number less than 10 plus 0 in front
def nums_pre(nums): """ Buy digital preprocessing, if single digit, plus 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 or blue ball fixation
Here, take the two simplest scenes of red ball fixation and blue ball fixation as an example. Other complex scenes can be expanded by themselves.
Red ball fixation
In the case of a fixed red ball, we only need to randomly generate a blue ball, then preprocess the data, and finally form a note number.
def gene_blue_random_ssq(reds, number): """ Red ball fixed, blue ball random :param reds: :param number: :return: """ result = [] for item in range(number): #Blue ball blue = random.randint(1, 16) #Red ball sort reds.sort() #Data preprocessing reds = nums_pre(reds) blue = nums_pre([blue])[0] result.append(' '.join(reds) + " + " + blue) return '\n'. join(result) Blue Ball Fixed
When the blue ball is fixed, we only need to randomly generate 6 different numbers from 1-33 to form the red ball.
def gene_red_random_ssq(blue, number): """ Blue ball fixed, red ball random :param blue: :param number: :return: """ result = [] for item in range(number): reds = [] 6 red balls while len(reds) < 6: #Take a random number from 1-33 temp_red_num = random.randint(1, 33) if temp_red_num not in reds: reds.append(temp_red_num) #Red ball sort reds.sort() #Data preprocessing reds = nums_pre(reds) blue = nums_pre([blue])[0] result.append(' '.join(reds) + " + " + blue) return '\n'.join(result)3. Crawl for winning numbers
Compared with the lottery, the lottery time of the two-color ball will be slightly longer. Brother omelette suggests choosing 10:30 p.m. to crawl.
Destination address:
aHR0cDovL2thaWppYW5nLjUwMC5jb20vc3RhdGljL2luZm8va2FpamlhbmcveG1sL3NzcS9saXN0LnhtbA==
This website displays the winning numbers of each issue of the past through XML data. We only need to match all the winning numbers using regular expressions and take the most recent issue number.
import reimport requestsclass SSQ(object): def __init__(self): #Please decode the specific address and replace it yourself self.url = '**/xml/ssq/list.xml' 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_ssq_lucky(self): #Initiate a request reponse = requests.get(url=self.url, headers=self.headers) #Regular rules 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.