# Randbetween of a list

Hi Team,
how can i do a randbetween of a list? its possible?
and then eliminate this number of the list.
br

You can use the function like this:

`RANDBETWEEN(1, COUNT([List]))`

Then use the INDEX function to get that item in the list:

`INDEX([List], RANDBETWEEN(1, COUNT([List])))`

Then you can subtract it from the original list but the item has to be in LIST form

`[List] - LIST(INDEX([List], RANDBETWEEN(1, COUNT([List]))))`

NOTE: I have not tested this

4 Likes

Good one. Nice practical solution.

Hi John Baer,
thks but,
br

[List] was my generic reference to some list variable. You need to replace it with whatever your list is. It could be a SELECT() function or a column of some LIST type like EnumList.

1 Like

Hi John,
I donâ€™t know where Iâ€™m wrong
iâ€™m attaching you 4 results.
and I dont know how to use index option?
br

In your examples, for each of the columns A, B, C and D, it seems you are reusing the RANDBETWEEN function each time which means it re-generating a new random number in each column.

You need to use the saved [randomNumber] value in columns C and D. For example in Column C the expression should be

`INDEX([initialList], [randomNumber])`

The expression in Column D should be:

`[initialList] - LIST(INDEX([initialList], [randomNumber]))`

1 Like

I quickly implemented this in a tester app. It appears to be working well. Note how it works when the list is not in sorted order.

4 Likes

thks a lot John for your help,
its running.

Hi John,
and now, how I can not repeat randomNumber? its possible?
My initial idea was to use [newList] as [initialList] but its impossible, its a circular definition and not works.

br

What are you trying to accomplish here? Something like shuffle play a playlist?

smart solution

Hi Steve,
I have 10 differents cards and 2 players, and i want to deal the cards.

Suppose a Cards table has the columns: Suit, Value, and ID (the combination of the suit and value); and 52 rows for a common deck of cards. To deal player 1, set Player 1 Hand to the output of:

``````TOP(ORDERBY(Cards[ID], RANDBETWEEN(1, 999999)), 5)
``````

and to deal player 2, set Player 2 Hand to the output of:

``````TOP(ORDERBY((Cards[ID] - [Player 1 Hand]), RANDBETWEEN(1, 999999)), 5)
``````

2 Likes

Hi Steave,
why using â€śTOP(ORDERBY(Cards[ID], RANDBETWEEN(1, 999999)), 5)â€ť,
appears this message â€śORDERBY has invalid inputsâ€ť?

br

Did you replace `Cards[ID]` with the appropriate column specification for your app?

Yes I did.
top(orderby(game[card],RANDBETWEEN(1, 999999)), 5)

The the Card column the key column of the Game table?

No Steve, key column is â€śrow_numberâ€ť.
To check it quickly i simplified situation using only one player.

Try:

``````top(orderby(game[_rownumber],RANDBETWEEN(1, 999999)), 5)
``````