A new code for a spectral-amplitude coding optical code-division multiple-access (OCDMA) system called the random diagonal (RD) code is proposed. This code is constructed using code segment and data segment. One of the important properties of this code is that the cross correlation at data segment is always zero, which means that phase intensity–induced noise (PIIN) is reduced. The performances of a RD realistic optical direct-sequence OCDMA network have been evaluated with PIIN and avalanche photodiode (APD) receivers. The comparison carried out included realistic system parameters, such as chromatic dispersion, multiple-access interference (MAI), receiver noises (dark current shot noise, and receiver thermal noise), and photodiode bandwidth. We analyze the error probability of the network taking into account these parameters. Bit-error rate (BER) performance is compared to Hadamard and modified frequency hopping (MFH) codes. It is shown that the system using this new code matrix not only suppresses PIIN, but also allows a larger number of active users compared to other codes. Simulation results show that using point-to-point transmission with three encoded channels, RD code using APD has better BER performance than PIN photodiode. Also, it is found that at 20 km the BER is 1.28×10-20 and 6.26×10-13 for APD and PIN photodiodes, respectively.