<?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>Random Value Generation</title><link>https://community.appian.com/discussions/f/general/8928/random-value-generation</link><description>Hi, I would like to know, is there any function available which can generate Integer random value, based on our specified range. As there is an function Available named as rand() which do not have any parameters, and returns the value of Type Number </description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/90568?ContentTypeID=1</link><pubDate>Wed, 02 Feb 2022 18:06:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:224e8268-77ff-4012-a95f-8273dd9003a1</guid><dc:creator>siddharthb0005</dc:creator><description>&lt;p&gt;joinarray(&lt;br /&gt;a!forEach(items: enumerate(ri!range),&lt;br /&gt;expression: char(65 + tointeger(rand()*(90-65)))),&lt;br /&gt;&amp;quot;&amp;quot;&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/76794?ContentTypeID=1</link><pubDate>Wed, 30 Sep 2020 15:48:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:74f082b0-819c-473d-96db-5055db9c5ff2</guid><dc:creator>paulg0001</dc:creator><description>&lt;p&gt;Stefan! Bravo, Sir, Bravo!&lt;br /&gt;&lt;br /&gt;This solution is incredible. I can&amp;#39;t thank you enough. You knocked it out of the park!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/76776?ContentTypeID=1</link><pubDate>Tue, 29 Sep 2020 05:39:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:22bcdaca-8625-4ce8-ad83-8a371769f58b</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;This is how you do it. Define your range of available characters first, then select randomly. ceiling() is important to make sure the lowest number is 1.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!chars: touniformstring({enumerate(10), char(65 + enumerate(26))}),
  joinarray(
    {
      1,
      index(local!chars, ceiling(rand(16) * 36), &amp;quot;-&amp;quot;)
    },
    &amp;quot;&amp;quot;
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/76774?ContentTypeID=1</link><pubDate>Tue, 29 Sep 2020 04:20:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:af1d7b09-3e9f-4bb5-88b2-afe46e92ec1f</guid><dc:creator>Siddharth</dc:creator><description>&lt;p&gt;Does this help ?&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!alpha: joinarray(
    {
      1,
      a!forEach(
        items: enumerate(
          16
        ),
        expression: {
          if(
            fixed(
              rand() * 2,
              0,
              true
            ),
            fixed(
              rand() * 10,
              0,
              true
            ),
            char(
              65 + tointeger(
                rand() * (
                  90 - 65
                )
              )
            )
          )
        }
      )
    }
  ),
  {
    local!alpha
  }
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/76766?ContentTypeID=1</link><pubDate>Mon, 28 Sep 2020 17:41:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c2f72d86-b403-4582-a636-a010ecce41d8</guid><dc:creator>paulg0001</dc:creator><description>&lt;p&gt;Hello again, Stefan!&lt;br /&gt;&lt;br /&gt;I used this advice to create a random alpha-numeric 17 character string [ the first character is always the number 1, followed by 16 random alpha-numeric characters. Ex:&amp;nbsp;&lt;span&gt;1UPJY54FL8YP3L760&lt;/span&gt; ]:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!alpha: joinarray(
    {
      1,
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      },
      {
        if(
          fixed(rand()*2, 0, true),
          fixed(rand()*10, 0, true),
          char(65 + tointeger(rand() * (90-65)))
        )
      }
    }
  ),
  {
    local!alpha
  }
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I want to know if this can be refactored &amp;amp; simplified to repeat this chorus n-times?:&lt;/p&gt;
&lt;p&gt;{&lt;br /&gt;&amp;nbsp; if(&lt;br /&gt;&amp;nbsp; &amp;nbsp; fixed(rand()*2, 0, true),&lt;br /&gt;&amp;nbsp; &amp;nbsp; fixed(rand()*10, 0, true),&lt;br /&gt;&amp;nbsp; &amp;nbsp; char(65 + tointeger(rand() * (90-65)))&lt;br /&gt;&amp;nbsp; )&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;This is how I imagined it would work (but doesn&amp;#39;t):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!alpha: reduce(
    if(
      fixed(rand()*2, 0, true),
      fixed(rand()*10, 0, true),
      char(65 + tointeger(rand() * (90-65)))
    ),
    {1},
    enum(16)
  ),
  local!alpha
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65878?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2019 06:53:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9b0b94cd-a229-4135-aa37-3e4c87dbed51</guid><dc:creator>divyaa0001</dc:creator><description>&lt;p&gt;Thank you so much..It helped. I changed it to single line:&amp;nbsp;index(ri!user,tointeger(fn!fixed(count(ri!user)*fn!rand()))+1,{})&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65769?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 19:09:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bc207203-ce98-413e-ad17-f2f426ef7a17</guid><dc:creator>PhilB</dc:creator><description>&lt;p&gt;In my experience they almost never want random, but load balanced... but the requirement definitely starts as &amp;quot;random&amp;quot;! :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65758?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 15:27:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dcc940d4-f00a-4b7d-8b98-bf15210d5bd3</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Maybe Divya is designing a game?&amp;nbsp; But seriously also I&amp;#39;ve had my customer request that the system semi-randomly assign certain things to users in the past, so I see this as a real potential business use case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65757?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 15:00:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:356dc5ad-5043-461c-a216-f320b536ad6a</guid><dc:creator>Robert Shankin</dc:creator><description>&lt;p&gt;Why are you randomly selecting users from a group?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65754?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 14:37:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:898d1170-0d5c-4a37-be52-8786bfa041cd</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;&lt;span&gt;Another option is&lt;/span&gt;&lt;span&gt;&amp;nbsp;tointeger(rand()*ri!range) .&amp;nbsp;&lt;/span&gt; If you&amp;#39;re going to be using rand() to pick a random item from a list,&amp;nbsp;you should use&amp;nbsp;tointeger(rand()*ri!range&amp;nbsp;&lt;strong&gt;+1&lt;/strong&gt;) to ensure that you don&amp;#39;t include 0 in the results (because when you round 0.1242287 to 1&amp;#39;s place you get 0) and you do include the top value of your range.&amp;nbsp; If you don&amp;#39;t include the +1 at the end you could find yourself running into errors due to Appian arrays starting at 1.&lt;/p&gt;
&lt;p&gt;You may also, depending on the method you use to convert to integer, see Appian rounding up and already including the top number of your range.&amp;nbsp; In that case, you may want to reduce your range by 1 so you don&amp;#39;t get 11 in your results on occasion when you want 1 - 10.&amp;nbsp;&amp;nbsp;If it&amp;#39;s vitally important that all random numbers be equally likely you may want to refine further how you convert response from rand() to an integer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65711?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2019 14:15:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f962720f-166f-49d3-bcee-796471f96418</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Yes. You&amp;#39;ll need to do this steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;get a list of all the Users you want to randomly select - let&amp;#39;s call this local!users&lt;/li&gt;
&lt;li&gt;derive the number of these - you can use fn!count() over the list from step 1&lt;/li&gt;
&lt;li&gt;generate a random number using fn!rand()&lt;/li&gt;
&lt;li&gt;multiply the count from step 2 by the value in step 3 - if the&amp;nbsp;result is 0 - because rand() can return 0 - then you&amp;#39;ll need to try again - let&amp;#39;s call this local!randUserIndex - you&amp;#39;ll need to&amp;nbsp;coerce the result into an integer - use&amp;nbsp;fn!integer(fn!fixed()) -&amp;nbsp; this value represents an random index into your list of users&lt;/li&gt;
&lt;li&gt;you can then simply return a user: local!users[local!randUserIndex]&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Hope this helps&lt;/p&gt;
&lt;p&gt;S&amp;gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/65709?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2019 13:29:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:94c0f669-3e81-413c-baad-b45d016fd5bb</guid><dc:creator>divyaa0001</dc:creator><description>&lt;p&gt;Is there a way to use rand(), to randomly select user from a group?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/40192?ContentTypeID=1</link><pubDate>Thu, 08 Dec 2016 15:34:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:736665c6-3c8d-4012-aa3b-98d4feaf7dcc</guid><dc:creator>shakilahd</dc:creator><description>Yup.. Thank You!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/40191?ContentTypeID=1</link><pubDate>Thu, 08 Dec 2016 15:20:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a81146be-8089-46b3-b634-3901ac6dac10</guid><dc:creator>aloks0189</dc:creator><description>@shakilahd You do something&lt;br /&gt;=====================================&lt;br /&gt;enumerate(10-6)+6&lt;br /&gt;=====================================&lt;br /&gt;&lt;br /&gt;Hope this will help you&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/40189?ContentTypeID=1</link><pubDate>Thu, 08 Dec 2016 14:50:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1a150b54-00cb-449b-8e45-99802a345140</guid><dc:creator>shakilahd</dc:creator><description>Hi.. is it possible to generate the series of number from specific range like 5 to 10 should returns 6,7,8,9.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/39679?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 10:39:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2e82aaad-dc6a-4cbc-9e91-bc51c64f0411</guid><dc:creator>Stefan Helzle</dc:creator><description>You are welcome :-)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/39678?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 10:39:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:36cf6faa-cfcf-4c93-8be9-5992a70153be</guid><dc:creator>aloks0189</dc:creator><description>Thank You @stefanh791&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random Value Generation</title><link>https://community.appian.com/thread/39677?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 10:33:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0536b1e0-12e3-47b6-b1c6-e1b63e1d0d27</guid><dc:creator>Stefan Helzle</dc:creator><description>Something like&lt;br /&gt;&lt;br /&gt;fixed(rand()*ri!range, 0)&lt;br /&gt;&lt;br /&gt;should do it.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>