In Python we can make a random array from 0 to 10 by doing:
randarray = random.sample(range(0, 10), 10)
My problem is that I want to create an array from 0 to 10, BUT in the first position I want to add a randomly generated number, and then append the rest of the numbers without repetition.
This means I first make:
first_value = random.randint(0,10)
and for example, if first_value is 4, I want to create a random array from 0 to 10 (without repetition) but ignoring number 4. For example, [0, 9, 5, 6, 1, 8, 7, 3, 2] . This is what I dont know how to do, so any help would be much appreciated.
Then I just want to append the first_value to randarray.
randarray.insert(0, first value)
So the desired output would be: [4, 0, 9, 5, 6, 1, 8, 7, 3, 2])
Aucun commentaire:
Enregistrer un commentaire