Need for predictable random generator

前端 未结 30 1114
情话喂你
情话喂你 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:38

    What about making the chance of critical depend on the last N attacks. One simple scheme is some kind of markov chain: http://en.wikipedia.org/wiki/Markov_chain but the code is very simple anyway.

    
    IF turns_since_last_critical < M THEN 
       critial = false
       turns_since_last_critical++;
    ELSE
       critial = IsCritical(chance);
       IF Critial THEN
           turns_since_last_critica = 0;
       ELSE
           turns_since_last_critica++;
       END IF;
    END IF;
    

    Of course you must make your maths because the chance of a critical is lower than the chance of a critical once you know that it has been enough turns since the last one

提交回复
热议问题