Python版微信红包分配算法
红包分配算法代码实现发给大家,祝红包大丰收!
#coding=gbk import random import sys #print random.randint(0, 99) #print "====", random.uniform(0, 0.99) def calRandomValue(min, max, total, num): print min, max, total, num total = float(total) num = int(num) min = 0.01 if(num return if num == 1: print "第%d个人拿到红包数为:%.2f" %(num, total) return i = 1 total_money = total #rtotal = (total*100 - min*num*100)/100 while( i max = total_money - min*(num- i) k = int((num-i)/2) if num -i k = num -i max = max/k monney = random.randint(int(min*100), int(max*100)) monney = float(monney)/100 total_money = total_money - monney print "第%d个人拿到红包数为:%.2f, 余额为: %.2f" %(i, monney, total_money) i += 1 print "第%d个人拿到红包数为:%.2f, 余额为: %.2f" %(i, total_money, 0.0) if __name__ == "__main__": min = sys.argv[1] max = sys.argv[2] total = sys.argv[3] num = sys.argv[4] calRandomValue(min, max, total, num)
python 2.py 0.01 10 20 30
0.01 10 20 30
第1个人拿到红包数为:1.34, 余额为: 18.66
第2个人拿到红包数为:1.06, 余额为: 17.60
第3个人拿到红包数为:1.08, 余额为: 16.52
第4个人拿到红包数为:0.98, 余额为: 15.54
第5个人拿到红包数为:0.88, 余额为: 14.66
第6个人拿到红包数为:0.48, 余额为: 14.18
第7个人拿到红包数为:0.26, 余额为: 13.92
第8个人拿到红包数为:0.90, 余额为: 13.02
第9个人拿到红包数为:0.12, 余额为: 12.90
第10个人拿到红包数为:0.41, 余额为: 12.49
第11个人拿到红包数为:0.43, 余额为: 12.06
第12个人拿到红包数为:0.63, 余额为: 11.43
第13个人拿到红包数为:0.36, 余额为: 11.07
第14个人拿到红包数为:0.25, 余额为: 10.82
第15个人拿到红包数为:1.38, 余额为: 9.44
第16个人拿到红包数为:0.17, 余额为: 9.27
第17个人拿到红包数为:0.79, 余额为: 8.48
第18个人拿到红包数为:0.52, 余额为: 7.96
第19个人拿到红包数为:0.44, 余额为: 7.52
第20个人拿到红包数为:1.15, 余额为: 6.37
第21个人拿到红包数为:0.13, 余额为: 6.24
第22个人拿到红包数为:0.76, 余额为: 5.48
第23个人拿到红包数为:1.32, 余额为: 4.16
第24个人拿到红包数为:0.80, 余额为: 3.36
第25个人拿到红包数为:0.16, 余额为: 3.20
第26个人拿到红包数为:0.27, 余额为: 2.93
第27个人拿到红包数为:1.82, 余额为: 1.11
第28个人拿到红包数为:0.45, 余额为: 0.66
第29个人拿到红包数为:0.27, 余额为: 0.39
第30个人拿到红包数为:0.39, 余额为: 0.00
以上所述就是本文的全部内容了,希望大家能够喜欢。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.
