<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://agiwiki.sierrahelp.com//index.php?action=history&amp;feed=atom&amp;title=Random</id>
	<title>Random - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://agiwiki.sierrahelp.com//index.php?action=history&amp;feed=atom&amp;title=Random"/>
	<link rel="alternate" type="text/html" href="http://agiwiki.sierrahelp.com//index.php?title=Random&amp;action=history"/>
	<updated>2026-12-02T22:14:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>http://agiwiki.sierrahelp.com//index.php?title=Random&amp;diff=13022&amp;oldid=prev</id>
		<title>Andrew Korson: Created page with &quot;The &#039;&#039;&#039;random&#039;&#039;&#039; command generates a random number within a specified range.  == Syntax ==  random(byt LOWER, byt UPPER, var vRESULT);  == R...&quot;</title>
		<link rel="alternate" type="text/html" href="http://agiwiki.sierrahelp.com//index.php?title=Random&amp;diff=13022&amp;oldid=prev"/>
		<updated>2019-04-19T12:25:16Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The &amp;#039;&amp;#039;&amp;#039;random&amp;#039;&amp;#039;&amp;#039; command generates a random number within a specified range.  == Syntax ==  random(&lt;a href=&quot;/index.php/Number&quot; title=&quot;Number&quot;&gt;byt&lt;/a&gt; LOWER, &lt;a href=&quot;/index.php/Number&quot; title=&quot;Number&quot;&gt;byt&lt;/a&gt; UPPER, &lt;a href=&quot;/index.php/Variable&quot; title=&quot;Variable&quot;&gt;var&lt;/a&gt; vRESULT);  == R...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The &amp;#039;&amp;#039;&amp;#039;random&amp;#039;&amp;#039;&amp;#039; command generates a random number within a specified range.&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
random([[number|byt]] LOWER, [[number|byt]] UPPER, [[variable|var]] vRESULT);&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The value of variable &amp;#039;&amp;#039;&amp;#039;vRESULT&amp;#039;&amp;#039;&amp;#039; is set to a pseudo random number between &amp;#039;&amp;#039;&amp;#039;LOWER&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;UPPER&amp;#039;&amp;#039;&amp;#039; inclusive. The algorithm  that AGI uses to generate random numbers is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;agi&amp;quot;&amp;gt;if (rndseed == 0)&lt;br /&gt;
  {&lt;br /&gt;
  rndseed = current_clock_count; [ use internal clock count as starting seed&lt;br /&gt;
  }&lt;br /&gt;
rndseed = (rndseed * 0x7C4D) mod 0xFFFF + 1;&lt;br /&gt;
vRESULT = LOWER + rndseed mod (UPPER - LOWER + 1);&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Possible Errors ==&lt;br /&gt;
&lt;br /&gt;
To work correctly, &amp;#039;&amp;#039;&amp;#039;UPPER&amp;#039;&amp;#039;&amp;#039; must be greater than or equal to &amp;#039;&amp;#039;&amp;#039;LOWER&amp;#039;&amp;#039;&amp;#039;. If If &amp;#039;&amp;#039;&amp;#039;LOWER&amp;#039;&amp;#039;&amp;#039; is greater than &amp;#039;&amp;#039;&amp;#039;UPPER&amp;#039;&amp;#039;&amp;#039;, then the returned value will be in the range 0 - 255. If  &amp;#039;&amp;#039;&amp;#039;LOWER&amp;#039;&amp;#039;&amp;#039; is exactly = &amp;#039;&amp;#039;&amp;#039;UPPER&amp;#039;&amp;#039;&amp;#039; + 1, it causes a divide by zero situation, which will [[crash AGI]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;agi&amp;quot;&amp;gt;&lt;br /&gt;
random(0, 10, v50);&lt;br /&gt;
print(&amp;quot;%v50 is greater than or equal to 0 &amp;quot;&lt;br /&gt;
      &amp;quot;AND less than or equal to 10&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Technical Information ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot;&lt;br /&gt;
| style=&amp;quot;background-color: #efefef&amp;quot; width=&amp;quot;200&amp;quot; | &amp;#039;&amp;#039;&amp;#039;Required Interpreter Version:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| width=&amp;quot;175&amp;quot; | Available in all AGI versions.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #efefef&amp;quot; | &amp;#039;&amp;#039;&amp;#039;Byte-Code Value:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| 130 (0x82 hex)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[Mathematical Commands]]&amp;lt;br /&amp;gt;&lt;br /&gt;
[[Category:Commands]]&amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Andrew Korson</name></author>
	</entry>
</feed>