The accuracy of a single shot is determined by multiple factors:
First, the weapon is aimed at a specific tile.
Then, the following formula is done for both x- and y-axis to get the final tile the shot will hit:
(<distance> * inaccuracy * 16 * <fireModeInaccuracyFactor> + <fixedInacurracy>) * <gaussian>
distance: is simply the distance to the intended target in tiles.
inaccuracy: the total inaccuracy of the ship (affected by crow's nest, telescope & targeting computer)
gaussian: A random value between -1 and 1 with values closer to 0 being more likely
Also, the the following shots get closer to the last one so the shots seem less random and more natural.