# How to generate the random list from available list data

Hello All,

I have created the below code. Not sure whether it’s optimal.

put [“Test 10”,“Test 100”,“Test 102”,“Test 104”,“Test 105”,“Test 106”,“Test 107”,“Test 112”,“Test 116”,“Test 117”,“Test 118”,“Test 119”,“Test 121”,“Test 122”,“Test 124”,“Test 125”,“Test 13”,“Test 130”,“Test 139”] into avaliable_Test_list

repeat 3 times
set Test_name_list to “”
insert any items of avaliable_Test_list into Test_name_list
insert any items of avaliable_Test_list into Test_name_list
insert any items of avaliable_Test_list into Test_name_list
end repeat
log Test_name_list

O/P : [“Test 106”,“Test 13”,“Test 139”]

But sometime the same number repeating twice. example.
[“Test 106”,“Test 13”,“Test 106”].

How to avoid ?

You can try to play with uniqueItems.

See below.

put [“Test 10”,“Test 100”,“Test 102”,“Test 104”,“Test 105”,“Test 106”,“Test 107”,“Test 112”,“Test 116”,“Test 117”,“Test 118”,“Test 119”,“Test 121”,“Test 122”,“Test 124”,“Test 125”,“Test 13”,“Test 130”,“Test 139”] into avaliable_Test_list

repeat 10 times
set Test_name_list to “”
insert any items of avaliable_Test_list into Test_name_list
insert any items of avaliable_Test_list into Test_name_list
insert any items of avaliable_Test_list into Test_name_list
put uniqueItems (Test_name_list) into newlist
end repeat

Log newlist

1 Like

There are a few ways to go about this. The simplest is just to shuffle the list into a random order:
`shuffle available_test_list`

Another way is to use `any item` to get a random item like you did, but use the `pull` command to remove it from the list at the same time. So something like this:

``````repeat until available_test_list is empty
pull any item of available_test_list into currentTest
// do something with currentTest here
end repeat``````
1 Like