The id is [ 0..(length-1)]!!

The old error was because the random was (0, max) when should be (0, max - 1); Sorry :D