Ranks and unranks permutations