import torch
import math


def rand_sphere(size):
    """
    Randomly sample on the sphere uniformly
    See http://corysimon.github.io/articles/uniformdistn-on-sphere/
    Our convention is 0 < theta < pi ; -pi < phi < pi
    :param size: torch.size or list of ints, size of returned tensors
    :return: theta, phi
    """
    theta = torch.acos(1 - 2 * torch.rand(size))
    phi = 2 * math.pi * torch.rand(size) - math.pi
    return theta, phi