#!/usr/bin/python
# coding:utf-8
# @Author:Rauck
import random
class WhoIsLuck:
"""
年会抽奖
"""
# 奖品
gift = [
{'name': '一等奖', 'limit': 3, 'desc': '泰国5日游+手术费报销'},
{'name': '二等奖', 'limit': 6, 'desc': 'iPhone14手机'},
{'name': '三等奖', 'limit': 30, 'desc': '三斤苹果'},
]
def __init__(self):
# 员工列表
self.users = list(range(0, 300))
def rand(self, grade):
limit = self.gift[grade]['limit']
luck_user = []
for i in range(0, limit):
while True:
u_index = random.randint(0, 299)
if u_index < len(self.users):
u = self.users[u_index]
break
luck_user.append(u)
# 中奖后就踢掉
self.users.remove(u)
print(f"{self.gift[grade]['name']},中奖用户分别是:", luck_user)
def main(self):
while True:
flag = input("是否执行三等级抽奖[yes|no]: ")
if flag == 'yes' or flag == 'y':
self.rand(2)
break
while True:
flag = input("是否执行二等级抽奖[yes|no]: ")
if flag == 'yes' or flag == 'y':
self.rand(1)
break
while True:
flag = input("是否执行一等级抽奖[yes|no]: ")
if flag == 'yes' or flag == 'y':
self.rand(0)
break
if __name__ == '__main__':
WhoIsLuck().main()
The Linux Kernel Module Programming Guide
Peter Jay Salzman, Michael Burian, Ori Pomerantz, Bob Mottram, Jim Huang译 断水客(WaterCutter)源 LKMPG
8 sysfs: 与模块交互
sysfs 允许用户通过读写模块中的变量实现与内核模块的交互。这个特性在…