抽獎模型設計程式碼
阿新 • • 發佈:2018-12-04
需求:
1:獎池獎品為 5、20、50、10000,每次投入10,抽獎10次,系統隨機反饋獎品或不反饋獎品,要求最終的產出投入比在0.85左右。
2:不得讓遊戲玩家通過歷史抽獎資料觀察出中獎規律
3:新玩家的中獎概率大於老玩家的中獎概率
4:解決玩家萬一抽中獎品10000,放棄遊戲,對平臺造成損失的情況
5:不得讓玩家過早抽中10000的獎品
from math import * import random from collections import Counter def game(nums,P,bits,game_gift): game_gift2=game_gift.copy() if 0 in game_gift2 and len(game_gift2)> 0: for i in game_gift2: if i == 0: game_gift2.remove(0) bis = -1 / 1000 * nums[1] + 0.2 if bis < 0: bis = 0 rand = random.random() datas = list(map(lambda x ,y: x*y-rand+bis, nums[0],P)) bit = datas.index(max(datas)) if max(datas)< 0 or \ (bits[1]>0.85 and bits[0]<1000) or \ nums[1]<6000 and gifts[bit] ==10000 or \ bits[2]>0.8 and (gifts[bit] ==10000 or random.random()<0.6 or (len(game_gift2)>0 and random.random()<0.9)or len(game_gift2)>3): gitf = 0 else: gitf = gifts[bit] return gitf ''' gifts = [5, 20, 50, 10000] bits = [20, 0.84, 0] nums = [[1, 1, 1, 1], 1] ''' def choujiang(nums,gifts,bits): P = list(map(lambda x: 1 / (10 * x), gifts)) game_gift = [] for k in range(10): c =game(nums,P,bits,game_gift) game_gift.append(c) for i in range(len(gifts)): if gifts[i] not in game_gift:nums[0][i] = nums[0][i]+ 1 else:nums[0][i] = floor(round(random.random(), 1) * nums[0][i]) nums[1] = nums[1]+ 1 # print(game_gift) return nums ,game_gift if __name__ == "__main__": gifts = [5, 20, 50, 10000] bit = [20, 0.84, 0] point = [] for j in range(10): data = [] nums = [[1, 1, 1, 1], 1] for i in range(8000): nums, c = choujiang(nums, gifts, bit) data.extend(c) bit[2] = sum(data) / len(data) print("第",i,"次抽獎的產出投入比為", sum(data) / len(data)) print("使用者", j, "中獎資料為", data) print("使用者", j, "中獎資料統計", Counter(data)) print("均值", sum(point) / len(point))
變數名寫的很隨意,請見諒。