added code for randperm