java - How to generate a distribution of k shots on n enemies -


i developing space combat game in java part of ongoing effort learn language. in battle, have k ships firing guns @ fleet of n of nefarious enemies. depending on how many of enemies hit how many of shots, (each ship fires 1 shot hits 1 enemy), damaged , destroyed. want figure out how many enemies hit once, how many hit twice , on, @ end have table looks this, 100 shots fired:

number of hits | number of occurences | total shots ----------------------------------------------------        1       |        30            |      30        2       |        12            |      24        3       |         4            |      12        4       |         7            |      28        5       |         1            |       5 

obviously, can brute force small numbers of shots , enemies randomly placing each shot on enemy , counting how many times each got shot @ end. method, however, impractical if i've got 3 million intrepid heroes firing on swarm of ten million enemies.

ideally, i'd way generate distribution of how many enemies hit number of shots. use random number generator pick point on distribution, , repeat process, increasing number of hits each time, until approximately shots accounted for. there general statistical distribution / way of estimating approximately how many enemies hit how many shots?

i've been trying work out birthday problem figure out probability of how many birthdays shared number of people, have not made significant progress.

i implementing in java.

edit: found simplification of may easier solve: what's distribution of probabilities n enemies not hit @ all? i.e. whats probability 0 not hit, 1 not hit, 2 not hit, etc.

it's similar problem, (ok, same problem simplification), seems might easier solve, , let me generate full distribution in couple of iterations.

you should take @ multinomial distribution, constraining case pi equal 1/k (be careful note wikipedia article swaps meaning of k , n).


previous attempt @ answer

maybe approach following fruitful:

  1. the probability a particular ship hit particular shot 1/n;
  2. the probability given ship hit once after k shots: h1 = 1/n (1-1/n)k-1;
  3. as above, twice: h2 = (1/n)2 (1-1/n)k-2, , on;
  4. expected number of ships hit once: n h1 , on.

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -