Using a single random number and a list, how would you return a random slice of that list?
For example, given the list [0,1,2] there are seven possibilities of random contiguous slices:
[ ][ 0 ][ 0, 1 ][ 0, 1, 2 ][ 1 ][ 1, 2][ 2 ]
Rather than getting a random starting index and a random end index, there must be a way to generate a single random number and use that one value to figure out both starting index and end/length.
Aucun commentaire:
Enregistrer un commentaire