Need for predictable random generator

前端 未结 30 1115
情话喂你
情话喂你 2020-11-27 09:04

I\'m a web-game developer and I got a problem with random numbers. Let\'s say that a player has 20% chance to get a critical hit with his sword. That means, 1 out of 5 hits

30条回答
  •  醉话见心
    2020-11-27 09:37

    Pre-calculate a random critical hit for each player.

    // OBJECT
    //...
    // OnAttack()
    //...
    c_h = c_h -1;
    if ( c_h == 0 ) {
     // Yes, critical hit!
     c_h = random(5) + 1 // for the next time
     // ...
    }
    

提交回复
热议问题