I have wanted to randomize list of strings, 9 different strings and then printing out the strings into unique set of four then exporting it into txt file. Here is what I have tried so far, but I am not sure how to set them into groups of four.
JavaScript
x
18
18
1
import random
2
a = "0xa5"
3
b = "0x1"
4
c = "0xE5924"
5
d = "0xE59"
6
e = "0xC60aE"
7
g = "0xd7F1DF"
8
h = "0xDEF1717"
9
i = "0xA102072A4C07F9"
10
j = "0x934A0E2c6C427D9F25"
11
12
13
14
my_list = [a,b,c,d,e,g,h,i,j]
15
random.shuffle(my_list)
16
myset = set(my_list)
17
print(myset)
18
I want the print outcome to come out in an example of:
JavaScript
1
3
1
["0xa5","0x1","0xE5924","0xE59"],
2
["0xa5","0x1","0xE5924","0xA102072A4C07F9"],
3
Advertisement
Answer
I did it with a while loop, just picking random numbers of the set you get.
JavaScript
1
9
1
oldarray= my_list
2
newarray=[]
3
count=0
4
while count<4:
5
num=random.randint(0,8)
6
newarray.append(oldarray[num])
7
count+=1
8
print(newarray)
9