<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=TI-BASIC%3ARand</id>
	<title>TI-BASIC:Rand - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=TI-BASIC%3ARand"/>
	<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=TI-BASIC:Rand&amp;action=history"/>
	<updated>2026-04-06T06:05:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=TI-BASIC:Rand&amp;diff=986&amp;oldid=prev</id>
		<title>Maintenance script: Initial automated import</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=TI-BASIC:Rand&amp;diff=986&amp;oldid=prev"/>
		<updated>2016-02-24T18:28:44Z</updated>

		<summary type="html">&lt;p&gt;Initial automated import&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Template:TI-BASIC:Command&lt;br /&gt;
|picture=RAND.GIF&lt;br /&gt;
|summary=Generates a random number between 0 and 1, or a list of such numbers. Can also be used to set the random number seed.&lt;br /&gt;
|syntax=rand&lt;br /&gt;
&lt;br /&gt;
rand(&amp;#039;&amp;#039;# of numbers&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;seed&amp;#039;&amp;#039;→rand&lt;br /&gt;
|location=Press:&lt;br /&gt;
# MATH to access the [[TI-BASIC:Math|Math]] menu.&lt;br /&gt;
# LEFT to access the PRB submenu.&lt;br /&gt;
# ENTER to select rand.&lt;br /&gt;
|compatibility=TI-83/84/+/SE&lt;br /&gt;
|size=1 byte&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
rand generates a uniformly-distributed pseudorandom number (this page and others will sometimes drop the pseudo- prefix for simplicity) between 0 and 1. rand(&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) generates a list of &amp;#039;&amp;#039;n&amp;#039;&amp;#039; uniformly-distributed pseudorandom numbers between 0 and 1. &amp;#039;&amp;#039;seed&amp;#039;&amp;#039;→rand seeds (initializes) the built-in pseudorandom number generator. The factory default seed is 0.&lt;br /&gt;
&lt;br /&gt;
[http://portal.acm.org/citation.cfm?doid=62959.62969 L&amp;#039;Ecuyer&amp;#039;s algorithm] is used by TI calculators to generate pseudorandom numbers.&lt;br /&gt;
&lt;br /&gt;
 0→rand&lt;br /&gt;
      0&lt;br /&gt;
 rand&lt;br /&gt;
      .9435974025&lt;br /&gt;
 rand(2)&lt;br /&gt;
      {.908318861 .1466878292}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; Due to specifics of the random number generating algorithm, the smallest number possible to generate is slightly greater than 0. The largest number possible &amp;#039;&amp;#039;is&amp;#039;&amp;#039; actually 1, but since returning a result of 1 would mess up the output of [[TI-BASIC:Randbin|RandBin(]] and [[TI-BASIC:Randnorm|RandNorm(]], the actual value returned in such cases is 1-1.11e-12 (which is displayed as 1, and is &amp;quot;equal&amp;quot; to 1 for the purposes of the [[TI-BASIC:Equal|=]] command).  To see 1, store 196164532 to rand and then run the random number generator.&lt;br /&gt;
&lt;br /&gt;
= Advanced Uses =&lt;br /&gt;
&lt;br /&gt;
To seed the random number generator, store a positive integer to rand (the command will ignore any decimals, and the sign of the number). Seeding the random number generator has several uses:&lt;br /&gt;
&lt;br /&gt;
When writing a program that uses random numbers, you may add a 0→rand instruction to the beginning of the program -- this ensures that the program&amp;#039;s actions will be repeatable, making it easier to fix a bug. Just don&amp;#039;t forget to take it out when you&amp;#039;ve finished writing the program.&lt;br /&gt;
&lt;br /&gt;
Seeding the random number generator can also be used to create fairly secure (unbreakable without a computer) encryption. Pick a secret key, and store it to rand as a seed. Then, perform some randomly generated manipulations on the data you want to encode -- for example, shifting each character of a string by a random number. Decoding the message is simple: store the secret key to rand and perform the opposite of those random operations. However, this is impossible to do if you don&amp;#039;t know the secret key.&lt;br /&gt;
&lt;br /&gt;
------&lt;br /&gt;
&lt;br /&gt;
When seeding the random number generator, as above, you make every random number generated afterwards predictable. This may be problematic even if your program doesn&amp;#039;t need random numbers, because other programs might. To prevent this, use the following code to save and restore &amp;quot;randomness&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{{Template:TI-BASIC:Prgm-code&lt;br /&gt;
|code=&lt;br /&gt;
:randInt(1,[[TI-BASIC:Size_75%}}E[[/size|Size_75%}}E[[/size]]9)→N&lt;br /&gt;
&lt;br /&gt;
(code that involves seeding the RNG here)&lt;br /&gt;
&lt;br /&gt;
:N→rand&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
------&lt;br /&gt;
&lt;br /&gt;
Since generating random numbers is a fairly time-consuming operation, the rand(&amp;#039;&amp;#039;# of numbers&amp;#039;&amp;#039;) syntax is very effective at generating a delay in your program -- just add the line:&lt;br /&gt;
&lt;br /&gt;
 :rand(N)&lt;br /&gt;
&lt;br /&gt;
The bigger N is, the longer the delay. In relation to the commonly used [[TI-BASIC:For|For(]] loop delay, the number used in the rand( delay is about 10 times smaller.  However, this code has a side effect of storing a list of random numbers to [[TI-BASIC:Ans|Ans]], which may be undesirable. To avoid this, use this somewhat longer line:&lt;br /&gt;
&lt;br /&gt;
 :If dim(rand(N))&lt;br /&gt;
&lt;br /&gt;
Despite the presence of an [[TI-BASIC:If|If]] statement, you don&amp;#039;t have to worry about the next line being skipped, since dim(rand(N)) will always be true.&lt;br /&gt;
&lt;br /&gt;
= Error Conditions =&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[TI-BASIC:Errors#domain|ERR:DOMAIN]]&amp;#039;&amp;#039;&amp;#039; if you try to generate a list of random numbers and the list length isn&amp;#039;t an integer 1-999.&lt;br /&gt;
&lt;br /&gt;
= Related Commands =&lt;br /&gt;
&lt;br /&gt;
* [[TI-BASIC:Randint|RandInt(]]&lt;br /&gt;
* [[TI-BASIC:Randbin|RandBin(]]&lt;br /&gt;
* [[TI-BASIC:Randnorm|RandNorm(]]&lt;br /&gt;
* [[TI-BASIC:Randm|RandM(]]&lt;br /&gt;
* [[TI-BASIC:Randintnorep|randIntNoRep(]][[Category:TI-BASIC]]&lt;br /&gt;
[[Category:TIBD]]&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>