import torch


def generate_noisy(x, nstd, random_seed=20180102):
    """
    This function generates noisy images from clear ones.
    Input:
        x: (N, C, H, W) 
        nstd: noise sigma added to clean image
    """
    shape = x.shape
    dtype = x.dtype
    sigma = nstd
    
    torch.manual_seed(random_seed)
    
    noise = sigma * torch.randn(*shape, dtype=dtype)
    
    x_noise = x + noise

    return x_noise.clamp(0.,1.)