Massive MIMO systems, where the base stations are equipped with hundreds of antenna elements, are an attractive way to attain unprecedented spectral efficiency in future wireless networks. In the "classical" massive MIMO setting, the terminals are assumed fully loaded and a main impairment to the performance comes from the inter-cell pilot contamination, i.e., interference from terminals in neighboring cells using the same pilots as in the home cell. However, when the terminals are active intermittently, it is viable to avoid inter-cell contamination by pre-allocation of pilots, while same-cell terminals use random access to select the allocated pilot sequences. This leads to the problem of intra-cell pilot contamination. We propose a framework for random access in massive MIMO networks and derive new uplink sum rate expressions that take intra-cell pilot collisions, intermittent terminal activity, and interference into account. We use these expressions to optimize the terminal activation probability and pilot length.