w3resource logo

:

Python Exercises

Python: Shuffle numbers between 0 and 10

Python NumPy: Random Exercise-6 with Solution

Write a Python program to shuffle numbers between 0 and 10 (inclusive).

Sample Solution :-

Python Code :

import numpy as np
x = np.arange(10)
np.random.shuffle(x)
print(x)
print("Same result using permutation():")
print(np.random.permutation(10))

Sample Output:

[2 7 1 5 3 9 0 4 6 8]                                                  
Same result using permutation():                                       
[8 9 0 4 7 3 1 6 5 2]

Python Code Editor:

Improve this sample solution and post your code through Disqus