Random sampling from exponential distribution C++


I want to sample at random from a tensor. For uniform distribution I use:

auto randtensor = torch::rand({100,1}); //Some tensor to sample from:

auto indices = torch::randint(0, 100, 10, torch::TensorOptions().dtype(torch::kInt64)); // 10 uniformly distributed random indices

auto random_sample = randtensor.index_select(0,indices); //10 random elements from randtensor, uniformly distributed

Now, instead of using a uniform distribution, I want to use an exponential distribution. Is there a way to generate random indices from an exponential distriburtion?


to my knowledge, there is direct way. You have to write your own index generator using exponential distribution and then create the tensor using generated indices.