Make randompos a common util function