A theory of random-matrix bases is presented, including expressions for orthogonality, completeness and the random-matrix synthesis of arbitrary matrices. This is applied to ghost imaging as the realization of a random-basis reconstruction, including an expression for the resulting signal-to-noise ratio. Analysis of conventional direct imaging and ghost imaging leads to a criterion which, when satisfied, implies reduced dose for computational ghost imaging. We also propose an experiment for x-ray phase contrast computational ghost imaging, which enables differential phase contrast to be achieved in an x-ray ghost imaging context. We give a numerically robust solution to the associated inverse problem of decoding differential phase contrast x-ray ghost images, to yield a quantitative map of the projected thickness of the sample.