First we must remember what a nucleosome is: a segment of DNA packed with proteins called histones. This is the initial step to turn the DNA a more compact structure. Citing the advantages of an extremely compact but flexible structure like chromosomes would make this answer a little longer (if you want, I can add them later), and to answer your question faster, we'd better keep moving on the discussion.
Epigenetics and gene expression are so beautiful that they have many mechanisms to regulate or change gene expression, and you mention one, which is done by reversible covalent modifications on histones. Such modifications are executed by especific proteins, that can do methylation, acetylation, phosphorilation in some aminoacids of histones.
When an aminoacid of a histone is linked with charged groups (e.g: methyl, acetyl) its charge is altered, and depending of the resulting charge (negative or positive), it can reduce or increase the afinity between the histone tail and the adjacent nucleosomes, and therefore, make the nucleosome more compact and less accessible or less compact and more accessible, respectively.
But the main effect of these covalent modifications on histones is that the groups added to the aminoacids act like markers indicating for proteins involved in expression (like transcriptional factors and RNA polymerase) that some genes are switched on or switched off. The patterns of this modifications (which one repress or estimulate gene expression) is not completely understood yet.
An example of how a certain region is chosen to be marked for expression or repression:
Consider an organism that has received a repressed gene related to obesity from its parents and this organism is lazy, eats a lot, has a sedentary life. As a result of all this stimulation, the proteins responsible for altering the histones of the gene related to obesity can be activated or recruited by others proteins, and make covalent modifications in a way that the histones of that gene now are marked for it to be expressed. This organism can pass the new mark to the its children and they will have propensity to obesity due to the activated gene. (This final example was an experiment of epigenetics using rats, I saw a long time ago, so I can't remember the reference).
And about if it's casual or not, the marks of regulation in a sequence of DNA can't be casual. For each one or two modifications of histones there is an enzyme that will only do its function if some event is already triggered or if it's triggered during the cell life depending on the environment the cell is exposed to. So millions of cells of a same tissue that have the same function would not have the same pattern of expression for the main genes related with that function by chance. Therefore, regulation of gene expression is very refined and histone marks are one of the many mechanisms that together dictate if a gene is repressed or expressed.