Hi All
How can I select some random names from a list, so that in next time, those previously selected names become omitted from the list?
for example, say we have 100 names in test.txt file, and we want to select 3 names randomly. then by recalling the selection function, we again select 3 names from remaining 97 names, and so on.
Please Note: I cant use pickle or cpickle, because I'm using python 2.2.2(pys60 1.45) on my phone and it doesnt support pickle.
here is my code, but every time I run it, it again selects from original 100 names.
f = open('e:\\test.txt', 'r')
names = f.readlines()
used = []
def shuffle(x):
i = len(x)
while i > 1:
i = i - 1
j = randrange(i)
x[j], x[i] = x[i], x[j]
return
def randSelect():
shuffle(names)
for i in xrange(3):
x = names[i]
if x not in used:
names.pop(i)
used.append(x)
print x
randSelect()
any help or suggestions is highly appreciated.