Question about the calculation of adding certain SNR background noise to audio in tutorial

The tutorial address is as followed:
https://pytorch.org/tutorials/beginner/audio_preprocessing_tutorial.html#adding-background-noise
The part confuses me most is in this picture:


My question is: how does this code work? what’s the principle of mathmatics and derivative process behind it?
Any reference is appreciated.