A list shows empty when it has one element in it!

I have been trying to modify my code to pick random numbers from a list (of 30 integers) without picking duplicates. The code has to do certain action when the list is empty (or all 30 elements have been used). But the list turns out be empty when it has still one element in it. Could you guys tell me what the problem is ?

How to pick a random item from a list without picking duplicates?


1 Like

I followed the very same tutorial. Everything works except the one I mentioned…

I am speculating here. Perhaps if the list is only 1, and you are bing an integer from 1 to 1, it returns nothing.


You can do an if length of list = 1 then… else do what you have.

1 Like

I dont understand. coz all 30 integers are going to be the index of 30 numbers in list…

get random integer from 1 to 1 (index is now 1)

from 1 to 1 might be causing the problem

So check if the list is 1 and process the last value. Otherwise process as you normally do

I’m still confused… :confused:

PIck a number between 1 and 1. there is nothing you can pick.

If the index value is 1, and you are asking to pick a number BETWEEN 1 and 1, you have no response.

That is my guess.

1 Like

So what could be the solution ?

I told you,

setup a check to see if the list length is 1. If it is, then process that last digit, and kick off your end of list process.

If not, process as you are doing it now.

I tried it with just one number… but its working :thinking:
I assume that ‘between 1 and 1’ there’s nothing left to choose other than the ‘1’ itself. So it will automatically be picked.

Ok, then setup a label to show the length of the index. just before it is picked.

Do you have a comma at the end of your list that is screwing it up?

No comma… does it has anything to do with initializing the local integer ‘index’ in 2 blocks (Next_Button.click & Web1.Got Text) ?

Nope, because that variable is local to that proceedure and does not pass through without being expressley set, which you have not.

We have to see what the index value is, so you need to setup a label to track it.

If it works as you said in a single value, clearly something is getting mismatched somewhere

How do I track the index value ?
The length of list is 30… before the other block is executed… do i have to check it for all index too…?

Each time you remove an item the list should go down b y one.

Set a lael to show the value.

I tried that… Its going down one by one, but the same issue as I mentioned above.

So you are saying at the end, the index is 1, but the random wont select it.

Yet when you do it as a standalone, it works fine?

Something is not the same.

when the index is ‘1’ what I see is a ‘Better Luck Next Time/Congrts’ page which is only to be displayed when the list is empty…

You have a prolem with those blocks, Show me the blocks in How and when the better luck shows up