lundi 27 février 2023

How to do probabilities in C

I need to take different probabilities and choose one. For instance: if you choose 1 the probabilities are as follows: Common 60% Rare 25% Ultra Rare 14% Super Super Rare 1% And each different choice by the "player" would change the probabilities to match how good/expensive their choice is (Its not necessary to share those probabilities since I can implement those myself after I figure this out). I know I need to use an srand statement but I don't know how to properly implement or even use an srand statement in this way. I'm still very new to coding and struggling real hard with some more basic subjects such as this.

I haven't tried much since I don't really understand srand statements and I haven't found much online that made sense to me or explained how to fix my problem. Below is the code I'm using, I've set up a switch statement for whatever the user selects but i need to then run like three probability calculations in there. For now I just want to implement the probability and result and I'll figure out the rest later. But how do I even run those probability calculations and then print out the result to the user?? Doubt my code here means much but it may help to explain what I'm doing, thanks.

  #include <stdio.h>
  #include <math.h>
  #include <stdlib.h>
  #include <time.h>
  int DoPull();

  int main(void) {
    int userInput;
  
    printf("Welcome to the gacha simulator!\n");
    printf("What type of pull will you do?\n");
    printf("1 = Normal Pull\n");
    printf("2 = Good Pull\n");
    printf("3 = Great Pull\n");
    printf("-1 = Leave\n");
    scanf("%d", &userInput);
  
      switch(userInput) {
      case 1:
        srand // listen man idk how to do srands i just have this set up for later
      break;
      case 2:
        srand
      break;
      case 3:
        srand
      break;
      case -1:
        printf("You left!\n");
        return 0;
      break; 
      default:
        printf("Invalid Input\n");
      break;
    }
    return 0;
  }

  int DoPull() {
  }



Aucun commentaire:

Enregistrer un commentaire