-
Notifications
You must be signed in to change notification settings - Fork 0
/
Random_set_inplace.py
33 lines (25 loc) · 980 Bytes
/
Random_set_inplace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
This program implements randomizing the set according to the priorities generated, here we will use inplace method.
"""
from random import *
try:
print "\n Enter the number of elements you wanna enter\n"
size = int(raw_input())
print "\n Enter the integer elements\n"
A=list()
for i in range(size):
A.append(int(raw_input()))
print "\n Input Array\n" ,A,"\n"
#B = []
for i in range(size):
rand_index = randrange(i,size) # +1 because randrange is closed open
print "\nRandom Index at iteration ",i,"=",rand_index
A[i],A[rand_index]=A[rand_index],A[i]
#B.append(A[random.randint(i,size)])
#A[i] = A[random.randint(i,size)]
print "\n Array after Sorting wrt Priority list"
print A,"\n\n"
#print B
except ValueError :
print "ERROR: \n Invalid Input\n"
exit(0)