import torch
import random


def one_hot_tensor(n: int) -> torch.Tensor:
    """ Sample a one hot vector of length n, return as a torch Tensor. """

    one_hot = torch.zeros(n)
    k = random.randrange(n)
    one_hot[k] = 1.0
    return one_hot