<?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>wanna fetch random number?</title><link>https://community.appian.com/discussions/f/general/34998/wanna-fetch-random-number</link><description>I have a list of integers from 1 to 100 and i want 30 random numbers from that list how can we do this?</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135498?ContentTypeID=1</link><pubDate>Fri, 17 May 2024 12:48:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e4d323e1-ba6a-4a50-8a72-6d9c901ef0fb</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Yep&amp;nbsp;the todatasubset() approach that Mike posted is the more general approach to sorting, but the rank() approach from my post works in a few scenarios like this where you&amp;#39;re sorting by numbers (and is slightly fewer lines of code) &lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135477?ContentTypeID=1</link><pubDate>Fri, 17 May 2024 01:00:27 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e54622ca-50ae-4784-8e63-027d87d07644</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;&amp;nbsp;&lt;a href="/members/peter.lewis"&gt;Peter Lewis&lt;/a&gt;&amp;nbsp;had also posted a solution for this problem a while ago I believe&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.appian.com/discussions/f/general/27881/generate-random-and-unique-numbers-for-a-specific-range"&gt;community.appian.com/.../generate-random-and-unique-numbers-for-a-specific-range&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135454?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 13:46:07 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5d25090f-a654-46e0-a58e-fbd4f24d15b1</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;thanks!&amp;nbsp; i believe someone else originally gave me the idea for the assignment of a randomized sort index to the original array - maybe you (not sure, sorry).&amp;nbsp; Credit where credit is due if it were possible, but I just re-typed it in this case from memory.&amp;nbsp; I think i&amp;#39;ll save it as a tool going forward though, it seems potentially useful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135452?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 13:32:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:98063c80-acc4-4bc3-ab88-e3c99a70c6e4</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;That&amp;#39;s a nice solution :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135444?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 13:05:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2783a781-4c3b-451b-8a48-0b0ae1a191f0</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;step 1: generate list of possible returns (this can be an enumerated list or any other list, for the sake of flexibility)&lt;/p&gt;
&lt;p&gt;step 2: create a &amp;quot;wrapper object&amp;quot; list where each list is assigned a random sort value&lt;/p&gt;
&lt;p&gt;step 3: sort by the sort value, essentially randomizing the list&lt;/p&gt;
&lt;p&gt;step 4: grab the first N results from the randomized list and return [note: paging lets us do this more easily]&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!myValues: enumerate(100)+1,  /* can be any list */
  local!numberToReturn: 30,  /* can be whatever you want */
  
  local!sortableObjectList: a!forEach(
    local!myValues,
    a!map(
      originalIndex: fv!index,
      sortValue: rand()*10,  /* resolves as decimal between 0 and 10, for readability */
      value: fv!item
    )
  ),
  
  local!sortedPage: todatasubset(
    arrayToPage: local!sortableObjectList,
    pagingConfiguration: a!pagingInfo(
      startIndex: 1,
      batchSize: local!numberToReturn,
      sort: a!sortInfo(
        field: &amp;quot;sortValue&amp;quot;,
        ascending: true()
      )
    )
  ),
  
  local!sortedPage.data.value
)&lt;/pre&gt;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/11/pastedimage1715864750282v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135417?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 10:35:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b40172bb-b2ff-46af-9112-b0a63faf59c5</guid><dc:creator>Konduru Chaitanya</dc:creator><description>&lt;p&gt;&lt;a href="/members/preetikam0001"&gt;PreetikA15&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just replace the enumerate to 30 instead of 15. Below is the same code what Stefan has mentioned.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!vals: tointeger(rand(100) * 50),
  index(
    union(local!vals, local!vals),
    enumerate(30) + 1,
    null
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135413?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 10:22:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5ee6a8b3-f5db-4db0-b250-b6f606196f5a</guid><dc:creator>venkatrea696188</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/11/pastedimage1715854823571v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;I think stefan got the answer for your question.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="/discussions/f/general/27881/generate-random-and-unique-numbers-for-a-specific-range"&gt;Look into this thread&lt;/a&gt;,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135412?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 10:19:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:63a76e4f-5f2b-4b0c-8c68-b260c1b38d9e</guid><dc:creator>PreetikA15</dc:creator><description>&lt;p&gt;thanks for your response, i want to duplicate to be removed too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: wanna fetch random number?</title><link>https://community.appian.com/thread/135411?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 10:11:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d088a12b-4cbf-4edf-9a4c-58824e727b6e</guid><dc:creator>venkatrea696188</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;tointeger(rand(30)*100)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Sometimes it gives duplicates, you want duplicates to be removed too??&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>