<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>functions expression rules</title><link>https://community.appian.com/discussions/f/general/23462/functions-expression-rules</link><description>for example, I am having 10 questions in my DB for that each question has a unique question id 
 If I enter 5 then 5 question id should be come randomly help me out on this</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89902?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 10:49:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c489de3b-86a9-49fa-a04d-98f1629cc5c3</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;This can be another approach. You generate a list of incremental random values, all unique. And then use that array to index from the list of available questions.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Below is the code for the same.&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!questionsData,
  local!array: 1 + tointeger(rand(5) * (1000 - 1)),
  local!sortedArray: rule!BAM_utils_sortArray(
    arrayValues_any: local!array,
    ascending_bool: true
  ),
  local!randomIndex: a!flatten(
    a!forEach(
      items: local!sortedArray,
      expression: wherecontains(fv!item, local!array)
    )
  ),
  index(
    local!questionsData,
    local!randomIndex,
    {}
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In local!array, I am trying to generate the values in a specific range. The parameter of rand() function will give us 5 values. You can change it to n.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89900?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 10:12:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7eccdc3b-9791-4cda-8ba1-b408f98adc01</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;It does what the name implies. It removes a random item from a given list.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89897?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:31:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b762af9b-cee8-4f34-adc3-93f4e2c44533</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;I tried out a nested loop, where the inner loop generates 5 random integers, and the out loop calls that 10k times. I then flattened the list of arrays and performed a union() on them, The underlying generated list is large enough to reduce the risk of ending up with a list of 4 or less unique integers, but very, very unlikely:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  /* local!questions here is the array of quiestions that you&amp;#39;d fetch from the DB*/
  local!questions: a!forEach(
    items: fn!enumerate(10) + 1,
    expression: &amp;quot;Q&amp;quot; &amp;amp; fv!item
  ),
  /* this is where the actual code starts*/
  local!randomNumbers: fn!union(
    tointeger(
      a!flatten(
        a!forEach(
          items: fn!enumerate(10000),
          expression: a!forEach(
            items: fn!enumerate(5) + 1,
            expression: fn!ceiling(fn!rand() * 10, 1)
          )
        )
      )
    ),
    tointeger({})
  )[{ 1, 2, 3, 4, 5 }],
  local!questions[local!randomNumbers]
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89896?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:29:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a0e6deb7-b0ef-44d7-95a3-30361b004169</guid><dc:creator>udhayakumarm000856</dc:creator><description>&lt;p&gt;what is the purpose for the rule u used in that line no 4&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89895?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:26:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9795716b-f9ee-40e3-8980-1560d691ddb4</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1642584376641v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Works for me. Can you explain the issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89894?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:23:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1ddf448a-d67a-4e65-9e5e-ca0c2a1d315a</guid><dc:creator>udhayakumarm000856</dc:creator><description>&lt;p&gt;This code is not working&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89893?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:19:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7677e87e-e068-47c0-90dc-ef3724241b14</guid><dc:creator>udhayakumarm000856</dc:creator><description>&lt;p&gt;it should come randomly means if there are 10 questions I want only 5 questions that is like not comes in ordering it should be like {10,1,5,3,8}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89892?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:14:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:835a5c15-d6df-461c-955f-74f7b4f937ad</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;This may create the same value multiple times. That was my first idea as well and I had no good idea to remove duplicates. I know that union does that, but then I would have to create more than 5 random numbers. But how much? With enough bad luck, all numbers are the same ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89891?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 09:05:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e2357d3e-e606-460a-9cc2-efea0cb7c2ea</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;An alternative would be to fetch all of the questions form the DB (agnostic of their database ids), and then generate a random list of 5 integers in the range of the size of the fetched array (ensuring no duplicate random integers are generated) and then use those to index your fetched array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89890?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 07:59:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b0486c55-374d-413a-bf53-0ef7b87a0a2f</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;My&amp;nbsp;quick solution is to fetch all the IDs from DB, then randomly remove items until only 5 are left.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!dbIds: {3,7,42,6,9,13,123,45,889,657},
  reduce(
    rule!TST_RemoveRandomItemFromList(_,_),
    local!dbIds,
    enumerate(5)
  )
)

TST_RemoveRandomItemFromList(
  list(Integer Array),
  dummy(Integer)
  
  remove(
    ri!list,
    ceiling(rand() * count(ri!list))
  )&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: functions expression rules</title><link>https://community.appian.com/thread/89886?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 06:46:07 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:31d88654-3fe8-44d0-89a6-3dd83e69a7bc</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;I do not understand this part.&amp;nbsp;&lt;/p&gt;
[quote userid="74089" url="~/discussions/f/general/23462/functions-expression-rules"]should be come randomly[/quote]
&lt;p&gt;But&amp;nbsp;what I think is&amp;nbsp;that, when you search for 5, you should get a question with id as 5.&amp;nbsp;&lt;br /&gt;For that, you use queryFilter() in query(). Documentation -&amp;nbsp;&lt;a href="https://docs.appian.com/suite/help/21.4/fnc_system_a_queryfilter.html"&gt;https://docs.appian.com/suite/help/21.4/fnc_system_a_queryfilter.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you want to combine it with any other filter, then try using logical expressions in query() function where you can pass multiple filters that can be applied all at the same time, or any of them.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I hope it helps.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br /&gt;Harshit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>