<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Finding the seeds</title>
		<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds</link>
		<description>Posts in the discussion thread &quot;Finding the seeds&quot; - A program to find the seed values that maximize the output of rand</description>
				<copyright></copyright>
		<lastBuildDate>Tue, 21 Jul 2026 20:08:46 +0000</lastBuildDate>
		
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-8317051#post-4048933</guid>
				<title>Re: Finding the seeds</title>
				<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds#post-4048933</link>
				<description></description>
				<pubDate>Sun, 04 Nov 2018 03:27:36 +0000</pubDate>
				<wikidot:authorName>lirtosiast</wikidot:authorName>				<wikidot:authorUserId>2005367</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The l'Ecuyer PRNG is a combination of two simpler multiplicative congruential generators (MCG), which each require a seed. On the calculator, as you can see from the code, the value in [0,10^9) seeds both MCGs, but is multiplied by 40014 for one of them, which probably slightly improves randomness. There's a special case for 0 because initializing the MCGs with 0 would cause them to yield all 0s.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-8317051#post-4048783</guid>
				<title>Re: Finding the seeds</title>
				<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds#post-4048783</link>
				<description></description>
				<pubDate>Sat, 03 Nov 2018 23:10:30 +0000</pubDate>
				<wikidot:authorName>Deoxal</wikidot:authorName>				<wikidot:authorUserId>4178723</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Sweet. I just want to ask if you understand why there are two seeds used in the original algorithm. That doesn't seem to be the case on the calculator unless the calculator divides the seed into two other numbers.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-8317051#post-4048776</guid>
				<title>Re: Finding the seeds</title>
				<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds#post-4048776</link>
				<description></description>
				<pubDate>Sat, 03 Nov 2018 22:41:17 +0000</pubDate>
				<wikidot:authorName>lirtosiast</wikidot:authorName>				<wikidot:authorUserId>2005367</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Not sure whether it's possible algebraically by hand, but stealing some code from the linked SO post, I wrote <a href="https://repl.it/@lirtosiast/Lecuyers-RNG-analysis">this c++ snippet</a> which finds all seeds that yield a value close to 0 or 1 on the <tt>i</tt>th iteration of rand. It runs in about 3 minutes.</p> <p>If you store <tt>S→rand</tt>, the actual seed is obtained by first applying <tt>int(abs(S))</tt>, then if the result is at least 10^9 or larger discarding the least significant digits. So there are only 10^9 seeds to search.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-8317051#post-4047211</guid>
				<title>Re: Finding the seeds</title>
				<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds#post-4047211</link>
				<description></description>
				<pubDate>Fri, 02 Nov 2018 05:24:32 +0000</pubDate>
				<wikidot:authorName>Deoxal</wikidot:authorName>				<wikidot:authorUserId>4178723</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Do you write code in TI Connect? If not, what do you use? I wasn't able to copy and paste your code into TIC and send it to my calculator since it said there was an invalid token. I had to copy it line by line to get it to send. From looking at your code it looks like it will take a very long time to terminate assuming <strong>N</strong> is greater than zero and less than or equal to one. I ran it in Wabbitemu at 1600% speed for 20 minutes and it didn't stop in that time. You are checking if a random number is equal to your selected number <strong>N</strong>, since real numbers are 18 bytes(144 bits) long I believe there is only a <strong>1 in 2<sup>144</sup></strong> or <strong>1 in 4.5*10<sup>44</sup></strong> chance of <strong>N</strong> equaling <strong>A</strong> on each iteration of the loop. Looking at the rest of your code, it looks you just counted the number of iterations of the first loop in B and reseeded the RNG. Finally, you iterated through the outputs of rand until you reach the one that made <strong>N=A</strong>.</p> <p>I wouldn't really call this predicting the output of rand. From what little I know about I cryptography I believe PRNGs do this:</p> <div class="code"> <pre><code>Input, S Random(S)→K Return Random(K) // This is pseudo code btw</code></pre></div> <p>And when you call it without arguments, there is actually an implicit argument, K:</p> <div class="code"> <pre><code>Random(K)→K Return Random(K) // Assume Random() is a pure function // K is only accessible to these code blocks</code></pre></div> <p>By doing this the next value used to calculate Random() is never actually exposed to <a href="https://en.wikipedia.org/wiki/Alice_and_Bob">Eve</a></p> <p>If Random() is not a strong RNG then you might be able to predict the next value of Random() without knowing K.</p> <p>P.S. I knew the sign of the seed didn't affect the output of rand but it wasn't relevant to the code I wrote, but the fact that non-integers are rounded down was.</p> <p>P.P.S Assuming I'm right about the odds I mentioned earlier then you are <strong>10<sup>35</sup></strong> times more likely to <a href="https://www.huffingtonpost.com/ronald-l-wasserstein/chances-of-winning-powerball-lottery_b_3288129.html">win the lottery</a> with a single ticket than for <strong>N</strong> to equal <strong>A</strong> on any iteration of your first loop.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-8317051#post-4047112</guid>
				<title>Re: Finding the seeds</title>
				<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds#post-4047112</link>
				<description></description>
				<pubDate>Fri, 02 Nov 2018 02:14:34 +0000</pubDate>
				<wikidot:authorName>CloudVariable</wikidot:authorName>				<wikidot:authorUserId>4590504</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>A few things:</p> <p>The seed values do not round to the integer. They round to the integer of the absolute value of the seed, meaning that all seeds are nonnegative integers (nonnegative instead of positive because 0 is a valid seed). This is to say that all valid seeds are natural numbers.</p> <p>I don’t know if this will help, but try looking at the patterns generated in the graph I found. My personal theory is that there exists an experimentally obtainable constant that represents the frequency of the sawtooth-like graph. As we saw in my earlier post, this wasn’t really a sawtooth like wave, but finding this constant might be a good place to start, and it will give us some good intuition for solving these pretty neat problems that we have come up with. I think that looking at the graphs that our algorithms produce would be a really good way to interpret the data.</p> <p>Also, here is a piece of code I came up with that might help. Given the seed and the last random number generated, it will output the next random number that you will generate. I have tested it for every TI 83 model.</p> <p>:Input “SEED: “,S<br /> :Input “NUMBER: “,N<br /> :S→rand<br /> :DelVar BDelVar A<br /> :Repeat A=N<br /> :rand→A<br /> :B+1→B<br /> :End<br /> :rand→D<br /> :S→rand<br /> :For(C,1,B<br /> :rand→A<br /> :End<br /> :Disp D<br /> D is the next number you will generate.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-8317051#post-4045736</guid>
				<title>Finding the seeds</title>
				<link>http://tibasicdev.wikidot.com/forum/t-8317051/finding-the-seeds#post-4045736</link>
				<description></description>
				<pubDate>Wed, 31 Oct 2018 15:35:40 +0000</pubDate>
				<wikidot:authorName>Deoxal</wikidot:authorName>				<wikidot:authorUserId>4178723</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>When reading the page on the <a href="http://tibasicdev.wikidot.com/rand">rand command</a> this piqued my interest:</p> <blockquote> <p>Note: Due to specifics of the random number generating algorithm, the smallest number possible to generate is slightly greater than 0. The largest number possible is actually 1, but since returning a result of 1 would mess up the output of randBin( and randNorm(, the actual value returned in such cases is 1-1.11e-12 (which is displayed as 1, and is &quot;equal&quot; to 1 for the purposes of the = command). To see 1, store 196164532 to rand and then run the random number generator.</p> </blockquote> <p>I'm a little confused about this statement since the output of rand is not used as the next value to compute rand since seeds are rounded down to an integer. Regardless, it and <a href="http://tibasicdev.wikidot.com/forum/t-8101641/the-random-seed-function">CloudVariable's post</a> inspired me to write this code.<br /> <strong>It's purpose is to record values of rand(and their seeds) that are greater than their predecessor's value.</strong></p> <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">+&nbsp;Show&nbsp;Code</a></div> <div class="collapsible-block-unfolded" style="display:none"> <div class="collapsible-block-unfolded-link"><a class="collapsible-block-link" href="javascript:;">-&nbsp;Hide&nbsp;Code</a></div> <div class="collapsible-block-content"> <div class="code"> <pre><code>Input &quot;RUN AT LAST VAL?&quot;,C // By setting C to 0, the program will initialize the needed variables. If C // Setting C to anything else the code will pick up where it left off, but if X, C, or the last values of Goto A // L₁ or L₂ have been modified you will most likely get an error and if not then inaccurate data. 1→X 0→rand 1→dim(L₁ 1→dim(L₂ X→L₁(1 1→C 1→⸤SAV(1 rand→L₂(1 Disp C,L₂(1 Lbl A ⸤SAV(1→X dim(L₁→C // This loop is the part I actually want to optimize. Repeat getKey=22 // Press [MODE] to safely exit the program. X→rand rand→A If A&gt;L₂(C // Checks to see if the new random value is larger than the last random value. Then C+1→C A→L₂(C // Saves the number to check against future values in A. X→L₁(C // Saves the seed used to generate the value in A. Disp &quot;&quot;,C,A End X+1→X End X→⸤SAV(1</code></pre></div> </div> </div> </div> <br /> <a href="https://drive.google.com/file/d/157LSzvlKkTTwiyvol5Jq1LJCjdvofglH/view?usp=sharing">Here is the uncommented version</a> if you want to run the program. <p>Obviously I'm looking for optimizations, but let me know if you think I have a bug anywhere as well.</p> <p>This program is essentially a brute force approach to finding the values I want, I'm interested in analyzing the <a href="https://stackoverflow.com/questions/32788122/ti-84-plus-random-number-generator-algorithm">algorithm</a> as well, but as of now I don't understand how to do that.<br /> <strong>I.E. is it possible to algebraically solve for seed values that output values close to 1, equal to 1, or the value closest to 0?</strong></p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>