Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //i'm bad at probabilistics so i brute forced this
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <iostream>
- using namespace std;
- int main(int ac, char** av){
- srand(0);
- uint stHitChance = RAND_MAX*0.4327;
- uint ndhitCahnce = RAND_MAX*0.5880;
- uint zeroHit=0;
- uint oneHit =0;
- uint twoHit =0;
- uint count=1000000;
- bool lightbearer=1;
- for(uint i=0;i<count;i++){
- bool noHit=1;
- uint curChance=stHitChance;
- uint hitRoll=rand();
- if(hitRoll<curChance){
- curChance=ndhitCahnce;
- oneHit++;
- noHit=0;
- }
- if(lightbearer){
- hitRoll=rand();
- if(hitRoll<curChance){
- oneHit-=curChance==ndhitCahnce;
- twoHit++;
- noHit=0;
- }
- }
- if(noHit){
- zeroHit++;
- }
- }
- printf("0 hit: %f \n",(double)zeroHit/count);
- printf("1 hit: %f \n",(double)oneHit /count);
- printf("2 hit: %f \n",(double)twoHit /count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement