To generate random, non-repeating numbers in Python, we can use the random module:
>>> import random
## Create a list
>>> list = [1.0 ,1.2 ,1.4.1.3.1.65]
>>> print(random.sample(list.3))1.3.1.65.1.2]
The result of ## is [1.3, 1.65, 1.2], which will be different for each execution
Copy the code
You can also scramble the list using this method by making the second argument the same length as the list.
>>> print(random.sample(list.5))1.0.1.3.1.2.1.4.1.65]
## Or you can do this:
>>> print(random.sample(list.len(list)))1.2.1.0.1.65.1.3.1.4]
Copy the code
The random module already has a shuffle() method to shuffle a list:
>>> random.shuffle(list)
>>> print(list)
[1.0.1.65.1.2.1.3.1.4]
Copy the code
You can then use sort() to sort the list from smallest to largest:
>>> list.sort()
>>> print(list)
[1.0.1.2.1.3.1.4.1.65]
Copy the code