# Randbetween of a list

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)
``````

This looks interesting. I don’t understand how passing a number as the 2nd argument to ORDERBY() works though? Is this an un-documented feature?

[card] as enum list type?

Hi Steve,
the result is ok for you? it seems ir running,
but for my use is not ok , i need another column with only the new card.

I attaches you an example [onlyCard].

br

It’s documented: