The ideal quantum key distribution (QKD) protocol requires perfect random numbers for bit encoding and basis selecting. Perfect randomness is of great significance to the practical QKD system. However, due to the imperfection of practical quantum devices, an eavesdropper (Eve) may acquire some random numbers, thus affecting the security of practical systems. In this paper, we analyze the effects of the weak randomness in the measurement-device-independent QKD (MDI-QKD) with finite resources. We analytically derive concise formulas for estimating the lower bound of the single-photon yield and the upper bound of the phase error rate in the case of the weak randomness. The simulation demonstrates that the final secret key rate of MDI-QKD with finite resources is sensitive to state preparation, even with a small proportion of weak randomness, the secure key rate has a noticeable fluctuation. Therefore, the weak randomness of the state preparation may bring additional security risks. In order to ensure the practical security of the QKD system, we are supposed to strengthen the protection of state preparation devices.
Sending-or-not sending twin-field quantum key distribution (SNS TF-QKD) has the advantage of tolerating large amounts of misalignment errors, and its key rate can exceed the linear bound of repeaterless quantum key distribution. However, the weak randomness in a practical QKD system may lower the secret key rate and limit its achievable communication distance, thus compromising its performance. In this paper, we analyze the effects of the weak randomness on the SNS TF-QKD. The numerical simulation shows that SNS TF-QKD can still have an excellent performance under the weak random condition: the secret key rate can exceed the PLOB boundary and achieve long transmission distances. Furthermore, our simulation results also show that SNS TF-QKD is more robust to the weak randomness loopholes than the BB84 protocol and the measurement-device-independent QKD (MDI-QKD). Our results emphasize that keeping the randomness of the states is significant to the protection of state preparation devices.