mardi 4 février 2020

Approches to implement a lottery program

Say I need to write a lottery program, say for each user at each attempt, 10% to win reward A, 20% for B, else nothing.

First approach:

  r = rand() //generate a rand number between [0,1)
  if r < 0.1 {
    // win A
  } else if r < 0.3 {
    // win B
  } else {
    // nothing
  }

Second approach:

  // generate an array containing 10% of A and 20% of B
  balls = [0,B,0,0,A,B,0,0,0,0]
  i = rand(0,10) // generate a rand number between [0,10)
  result = balls[i] // this is if you win or not

I'm wondering statistically if these two are identical (I think so). Or, both are flawed maybe?




Aucun commentaire:

Enregistrer un commentaire