question

Bing L avatar image
0 Likes"
Bing L asked Ryan Clark commented

order by query

In pull from list activity,I want the query condition is ORDER BY RAND() and ORDER BY num ASC,but,It did not work as pic settings,how could I achieve it? thanks1647796330(1).jpg

FlexSim 22.0.1
pull from list
16477963301.jpg (20.9 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ryan Clark avatar image Ryan Clark commented ·

Hi @Bing L, was one of Bing L's or Felix Möhlmann's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Felix Möhlmann edited

That query seems to work fine for me. The tokens are created with labels in the order of GlobalTable1 (Col 1 => num). GlobalTable2 shows the order in which they were pulled.

1647798661918.png

Could you provide some more detail in what way the query doesn't work in your model?


1647798661918.png (93.7 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Bing L avatar image Bing L commented ·

thank you.

My goal is to pull 3 random numbers from 10 nunbers, but these 3 numbers must be arranged ORDER BY ASC

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Bing L commented ·

The query is applied to the list before something is pulled. Whereas you want to order the resulting array after pulling.

You could theoretically use multiple "Pull from List" in a row and use the pull from the previous one as a condition in the next, but this would introduce a bias toward higher numbers since some entries would be disqualified from being pulled after the first one.

Instead I would simply sort the resulting array after all entries are pulled. The code below is an implementation of a simple sorting algorithm (bubble sort) that you can use to do this. It assumes that "num" is a label on the entries that are pulled and that the pulled entries are assigned to "token.pulled".

Array pulled = token.pulled;
for(int i = pulled.length; i > 1; i--)
{
   for(int j = 1; j < i; j++)
   {
      if(pulled[j].num > pulled[j+1].num)
      {
         Variant memory = pulled[j];
         pulled[j] = pulled[j+1];
        pulled[j+1] = memory;
     }
  }
}
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.