C++程序,逻辑非常简单,概率算法不严谨,但是模拟一下没问题。
可以让偶尔头脑发热的你冷静一下。
// An highlighted block #include<iostream> #include<ctime> #include<cstdlib> using namespace std; int GetRandomNumber() { int RandomNumber; //time()用系统时间初始化种。为rand()生成不同的随机种子。 RandomNumber = rand() % 100 + 1;//生成1~100随机数 return RandomNumber; } void play(int count[3],int legend[3]) { int Skinfragments = count[2]; int HonorPoint = count[1]; int Coupon = count[0]; int s3 = legend[2]; int s2 = legend[1]; int s1 = legend[0]; int num =GetRandomNumber(); // cout << num << endl; //test if (num < 3) { //传说皮肤*3 //三个输出为不同的字符串、表现为均分2%概率 float x = GetRandomNumber()/100.0;//0~1的随机数 // cout<< x << endl; if (x < 0.34) if (s1 == 0) { cout << "【黄金狮子座*达摩】" << endl; s1=1; } else { cout << "Re:传说皮肤" << endl; Skinfragments += 5; } else if (x < 0.67) if (s1 == 0) { cout << "【黄金射手座*后羿】" << endl; s2=1; } else { cout << "Re:传说皮肤" << endl; Coupon += 1; } else if (s3 == 0) { cout << "【黄金白羊座*张良】" << endl; s3=1; } else { cout << "Re:传说皮肤" << endl; HonorPoint += 30 ; } } else if (num < 45) { //荣耀积分 20/30 两种情况 float x = GetRandomNumber() / 100.0;//0~1的随机数 // cout << x << endl; if (x < 0.5) HonorPoint += 20; else HonorPoint += 30; //cout << "荣耀积分*" << HonorPoint << endl; } else if (num < 77) { //积分夺宝抵用券 Coupon++; //cout << "积分夺宝抵价券*" << Coupon << endl; } else { //皮肤碎片 1/2/5 float x = GetRandomNumber() / 100.0;//0~1的随机数 // cout << x << endl; if (x < 0.34) Skinfragments++; else if (x < 0.67) Skinfragments += 2; else Skinfragments += 5; //cout << "皮肤碎片*" << Skinfragments << endl; } count[0] = Coupon; count[1] = HonorPoint; count[2] = Skinfragments; legend[0] = s1; legend[1] = s2; legend[2] = s3; } void display(int count[3]) { cout << "<<<"; if(count[0]!=0) cout << "积分夺宝抵价券*" << count[0] <<"\t"; if(count[1]!=0) cout << "荣耀积分*" << count[1] << "\t"; if(count[2]!=0) cout << "皮肤碎片*" << count[2] ; cout<<">>>"<<endl; cout << "====================================================="<< "\n\n\n"; } int instruction() { int num; cout << "购买数量:"; cin >> num; int cost; cost = num * 50; cout << "所需点券数:" << cost<<endl; cout << "消费:" << cost / 10 << "元" << endl; int real = num / 10 + num; cout << "实际抽取数量" << real<<endl; cout << "=======================抽取结果======================"<<endl; return real; } int main() { int Skinfragments=0, HonorPoint=0, Coupon=0; int count[3] = { Coupon, HonorPoint, Skinfragments }; int instruct=instruction(); srand((unsigned)time(NULL)); int l1 = 0, l2 = 0, l3 = 0; int legend[3] = { l1,l2,l3 }; for (int i = 0; i < instruct; i++) { //cout << GetRandomNumber()/100.0 << endl; play(count,legend); } display(count); return 0; }
永久皮肤概率2%
皮肤碎片:24.4%
荣耀积分:41.6%
积分夺宝抵用券:32%