<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://channelf.se/veswiki/index.php?action=history&amp;feed=atom&amp;title=Snippet%3APseudorandom_numbers</id>
		<title>Snippet:Pseudorandom numbers - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://channelf.se/veswiki/index.php?action=history&amp;feed=atom&amp;title=Snippet%3APseudorandom_numbers"/>
		<link rel="alternate" type="text/html" href="http://channelf.se/veswiki/index.php?title=Snippet:Pseudorandom_numbers&amp;action=history"/>
		<updated>2026-06-03T12:15:20Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>http://channelf.se/veswiki/index.php?title=Snippet:Pseudorandom_numbers&amp;diff=554&amp;oldid=prev</id>
		<title>E5frog: Created page with &quot;Sometimes you want to add a random number to your programming but you will have to make your own code to produce it. &lt;br&gt; A common way to make a pseudo-random number generator...&quot;</title>
		<link rel="alternate" type="text/html" href="http://channelf.se/veswiki/index.php?title=Snippet:Pseudorandom_numbers&amp;diff=554&amp;oldid=prev"/>
				<updated>2020-01-03T11:56:30Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;Sometimes you want to add a random number to your programming but you will have to make your own code to produce it. &amp;lt;br&amp;gt; A common way to make a pseudo-random number generator...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Sometimes you want to add a random number to your programming but you will have to make your own code to produce it. &amp;lt;br&amp;gt;&lt;br /&gt;
A common way to make a pseudo-random number generator (PRNG) is do use a Linear Feedback Shift Register (LFSR). &amp;lt;br&amp;gt;&lt;br /&gt;
This will give you a series of numbers from 0 to 255 in a seemingly randomized order. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will however get the same series of values in the same order every time, your &amp;quot;seed&amp;quot; number will choose the start position.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here's an example of a subroutine with 8-bit LFSR:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
; In this example the pseudo random number is stored in register 1&lt;br /&gt;
; Also uses register 0 for temporary storage&lt;br /&gt;
&lt;br /&gt;
LFSR:             ; Linear Feedback Shift Register&lt;br /&gt;
	clr&lt;br /&gt;
	as	1&lt;br /&gt;
	bz	doEor&lt;br /&gt;
	lr	0, A		; Save original number in r0&lt;br /&gt;
	sl	1		; shift one step left&lt;br /&gt;
	lr	1, A&lt;br /&gt;
	bz	noEor&lt;br /&gt;
&lt;br /&gt;
	; Do XOR if b7 was 1, workaround for missing carry on &amp;quot;sl&amp;quot; &lt;br /&gt;
	lr	A, 0&lt;br /&gt;
	ni	%10000000&lt;br /&gt;
	bz	noEor&lt;br /&gt;
&lt;br /&gt;
doEor:&lt;br /&gt;
	lr	A, 1&lt;br /&gt;
	xi	$2b     ; Do the XOR thing&lt;br /&gt;
	lr	1, A&lt;br /&gt;
noEor:&lt;br /&gt;
	pop&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value used with XOR-function is $2B here, one of these other values can be used to give a different 256 byte non-repeating chain of values. &amp;lt;br&amp;gt;&lt;br /&gt;
$1d, $2b, $2d, $4d, $5f, $63, $65, $69, $71, $87, $8d, $a9, $c3, $cf, $e7, $f5&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using $2B as XOR value the data will be this:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:LFSR_%242B.png]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
When using $71 as XOR value the data will be this:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:LFSR_%2471.png]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://codebase64.org/doku.php?id=base:small_fast_8-bit_prng CodeBase64 used for reference]&lt;/div&gt;</summary>
		<author><name>E5frog</name></author>	</entry>

	</feed>