<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I generate a random number between a specific range? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565062#M196843</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/151437"&gt;@worshamn&lt;/a&gt;&amp;nbsp;Kudos! Building on your solution I slightly simplified the math.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| eval rand = random() % (high - low + 1) + low
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Aug 2021 13:20:37 GMT</pubDate>
    <dc:creator>gbhatti</dc:creator>
    <dc:date>2021-08-27T13:20:37Z</dc:date>
    <item>
      <title>How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378229#M167489</link>
      <description>&lt;P&gt;Hi, How can I generate a random number between 1 to 20. I random() function doesn't allow to specify a range. please help&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 20:33:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378229#M167489</guid>
      <dc:creator>sravani27</dc:creator>
      <dc:date>2018-09-18T20:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378230#M167490</link>
      <description>&lt;P&gt;Try using the modulo operator.  For example, &lt;CODE&gt;... | eval rand=(random() % 20) + 1 | ...&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 20:43:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378230#M167490</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-09-18T20:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378231#M167491</link>
      <description>&lt;P&gt;Building a bit on @richgalloway 's answer I believe this works and allows you to set the high and low range. I added just some extra fluff for testing, your eval line could just look line 4 with high and low replaced with your range:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval high = 100
| eval low = 10
| eval rand = round(((random() % high)/(high)) * (high - low) + low)
| eval inRange = if(rand &amp;lt;= high AND rand &amp;gt;= low, "True", "False")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 19:50:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378231#M167491</guid>
      <dc:creator>worshamn</dc:creator>
      <dc:date>2018-09-26T19:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378232#M167492</link>
      <description>&lt;P&gt;@ppablo_splunk , this one should get moderator-answered.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 10:51:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/378232#M167492</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-20T10:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565062#M196843</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/151437"&gt;@worshamn&lt;/a&gt;&amp;nbsp;Kudos! Building on your solution I slightly simplified the math.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| eval rand = random() % (high - low + 1) + low
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 13:20:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565062#M196843</guid>
      <dc:creator>gbhatti</dc:creator>
      <dc:date>2021-08-27T13:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565064#M196844</link>
      <description>&lt;P&gt;One thing - in case of small ranges it might be negligible but if you want a random number from a big range (like between 0 and 1.5*2^30) performing a modulo on random() will not give you uniform distribution.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 13:30:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565064#M196844</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-08-27T13:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between a specific range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565065#M196845</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;I was not aware of this. Thanks for pointing it out.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 13:40:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-a-random-number-between-a-specific-range/m-p/565065#M196845</guid>
      <dc:creator>gbhatti</dc:creator>
      <dc:date>2021-08-27T13:40:39Z</dc:date>
    </item>
  </channel>
</rss>

