<?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>Piotr Gabryjeluk dev blog</title>
		<link>http://piotr.gabryjeluk.pl</link>
		<description>Blog, photos and developer notes of Piotr Gabryjeluk, one of Wikidot.com developers.</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 11 Feb 2012 22:29:23 +0000</lastBuildDate>
		
					<item>
				<guid>http://piotr.gabryjeluk.pl/dev:bash-http-server-evolves</guid>
				<title>BASH HTTP server evolves</title>
				<link>http://piotr.gabryjeluk.pl/dev:bash-http-server-evolves</link>
				<description>

&lt;p&gt;Some time ago, mainly for fun I created &lt;a href=&quot;http://piotr.gabryjeluk.pl/www-server-in-100-lines-bash-script&quot;&gt;a HTTP server in just BASH and netcat&lt;/a&gt;. The aim was to instantly and simply share files between computers in local network with a one-line command:&lt;/p&gt;
&lt;div class=&quot;code&quot;&gt;
&lt;pre&gt;
&lt;code&gt;quake@vaio /home/quake/files $ http_server.sh 8000&lt;/code&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And voila, the files in directory /home/quake/files are accessible via a web browser (or a wget command) on every computer in local network.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=2462&amp;amp;size=small&amp;amp;timestamp=1328999362&quot; alt=&quot;Gabrys&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=2462)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;Gabrys&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Tue, 31 Jan 2012 18:34:37 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Some time ago, mainly for fun I created <a href="http://piotr.gabryjeluk.pl/www-server-in-100-lines-bash-script">a HTTP server in just BASH and netcat</a>. The aim was to instantly and simply share files between computers in local network with a one-line command:</p> <div class="code"> <pre> <code>quake@vaio /home/quake/files $ http_server.sh 8000</code> </pre></div> <p>And voila, the files in directory /home/quake/files are accessible via a web browser (or a wget command) on every computer in local network.</p> <div class="content-separator" style="display: none:"></div> <p>Some time ago I learned I can achieve the same effect using simple Python one-liner:</p> <div class="code"> <pre> <code>python -m SimpleHTTPServer</code> </pre></div> <p>This work for standard Python 2.x installations, for Python 3.x even simpler:</p> <div class="code"> <pre> <code>python -m http.server</code> </pre></div> <p>No need for custom scripts, netcat or other fancy stuff, you need just a standard Python installation and it works ;-).</p> <p>But recently I faced a challenge of copying many gigabytes of files over network. Copying files over SSH was too slow (data is copied from an ARM machine, not really blazing fast at encryption stuff). I tried to copy files over FTP, but I failed at configuring read-write FTP server in limited time. I wanted to avoid configuring other fancy file servers like Samba/CIFS. I could use NFS, which is both simple to configure and fast enough, but I decided to go more fancy.</p> <p>I took my old <strong>http_server.sh</strong>, tweaked it a bit (including replacing lame <tt>cat &quot;$file&quot; | wc -c -</tt> with <tt>stat -c %s</tt> to determine file size and replacing <tt>gawk</tt> with <tt>awk</tt> in the script) and then created a specialised version of it: <strong>tar_server.sh</strong>.</p> <p>tar_server.sh is a HTTP server based on http_server.sh that shows you list of directories inside of directory it was run from and allows you to download the directories as tar files. It does the taring on the fly, so you don't waste the disk space.</p> <p>It's as simple as:</p> <div class="code"> <pre> <code>quake@vaio /home/quake/files $ tar_server.sh 8000</code> </pre></div> <p>Then you can see the list of tar files to download at <a href="http://your_ip:8000/">http://your_ip:8000/</a> . Suppose you have a directory /home/quake/files/backup. You can download it on some other machine using:</p> <div class="code"> <pre> <code>quake@other-machine /home/someuser/files $ wget http://your_ip:8000/backup.tar</code> </pre></div> <p>Or to unpack on the fly:</p> <div class="code"> <pre> <code>quake@other-machine /home/someuser/files $ wget http://your_ip:8000/backup.tar -O - | tar -x</code> </pre></div> <p>This way you can mirror part of your filesystem with almost no dedicated tools. The script is quite OS-independent and requires only netcat, awk, tar and stat commands, that are likely to found in any Unix-like systems.</p> <p>Also the script proves BASH is still very useful tool and adapting simple scripts is easy and FUN :-).</p> <p>Remember, the scripts (just like original version) can handle only one client at once, so if you want to do parallel stuff, you need to launch more of them on different port each.</p> <p>Here are the scripts:</p> <h2><span>http_server.sh:</span></h2> <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">+&nbsp;show&nbsp;block</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;block</a></div> <div class="collapsible-block-content"> <div class="code"> <pre> <code>#!/bin/bash function debug { local severity=&quot;$1&quot; shift local message=&quot;$@&quot; echo -n &quot;`date -u`&quot; 1&gt;&amp;2 echo -ne '\t' 1&gt;&amp;2 echo -n &quot;$severity&quot; 1&gt;&amp;2 echo -ne '\t' 1&gt;&amp;2 echo &quot;$message&quot; 1&gt;&amp;2 } function fix_path { echo -n &quot;$1&quot; | head -n 1 | sed 's|^[/.]*||' | sed 's|/\.*|/|g' } function serve_dir { local dir=&quot;`fix_path &quot;$1&quot;`&quot; if [ &quot;$dir&quot; = &quot;&quot; ]; then dir=&quot;./&quot; fi echo 'HTTP/1.1 200 OK' echo 'Content-type: text/html;charset=UTF-8' echo echo LISTING &quot;$dir&quot; echo '&lt;br/&gt;' ls -p &quot;$dir&quot; | sed -e 's|^\(.*\)$|&lt;a href=&quot;/'&quot;$dir&quot;'\1&quot;&gt;\1&lt;/a&gt;&lt;br/&gt;|' } function serve_file { local file=&quot;`fix_path &quot;$1&quot;`&quot; echo 'HTTP/1.1 200 OK' echo 'Content-type: application/x-download-this' echo 'Content-length: '&quot;`stat -c %s &quot;$file&quot;`&quot; echo debug INFO serving file &quot;$file&quot; cat &quot;$file&quot; } function process { local url=&quot;`awk '{print $2}' | head -n 1`&quot; case &quot;$url&quot; in */) debug INFO Processing &quot;$url&quot; as dir serve_dir &quot;$url&quot; break ;; *) debug INFO Processing &quot;$url&quot; as file serve_file &quot;$url&quot; ;; esac } function serve { local port=&quot;$1&quot; local sin=&quot;$2&quot; local sout=&quot;$3&quot; while debug INFO Running nc; do nc -l -p &quot;$port&quot; &lt; &quot;$sin&quot; &gt; &quot;$sout&quot; &amp; pid=&quot;$!&quot; debug INFO Server PID: &quot;$pid&quot; trap cleanup SIGINT head -n 1 &quot;$sout&quot; | process &gt; &quot;$sin&quot; trap - SIGINT debug INFO Killing nc kill &quot;$pid&quot; done debug INFO Quiting server } function cleanup { debug INFO Caught signal, quitting... rm -Rf &quot;$tmp_dir&quot; exit } tmp_dir=&quot;`mktemp -d -t http_server.XXXXXXXXXX`&quot; sin=&quot;$tmp_dir&quot;/in sout=&quot;$tmp_dir&quot;/out pid=0 port=&quot;$1&quot; mkfifo &quot;$sin&quot; mkfifo &quot;$sout&quot; debug INFO Starting server on port &quot;$port&quot; serve &quot;$port&quot; &quot;$sin&quot; &quot;$sout&quot;</code> </pre></div> </div> </div> </div> <h2><span>tar_server.sh:</span></h2> <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">+&nbsp;show&nbsp;block</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;block</a></div> <div class="collapsible-block-content"> <div class="code"> <pre> <code>#!/bin/bash function debug { local severity=&quot;$1&quot; shift local message=&quot;$@&quot; echo -n &quot;`date -u`&quot; 1&gt;&amp;2 echo -ne '\t' 1&gt;&amp;2 echo -n &quot;$severity&quot; 1&gt;&amp;2 echo -ne '\t' 1&gt;&amp;2 echo &quot;$message&quot; 1&gt;&amp;2 } function fix_path { echo -n &quot;$1&quot; | head -n 1 | sed 's|^[/.]*||' | sed 's|/\.*|/|g' } function serve_dir { echo 'HTTP/1.1 200 OK' echo 'Content-type: text/html;charset=UTF-8' echo find -type d -mindepth 1 -maxdepth 1 | sed -e 's|^\./||' -e 's|^\(.*\)$|&lt;a href=&quot;/\1.tar&quot;&gt;\1.tar&lt;/a&gt;&lt;br/&gt;|' } function serve_file { echo 'HTTP/1.1 200 OK' local file=&quot;`fix_path &quot;$1&quot;`&quot; local dir=&quot;`echo &quot;$file&quot; | sed 's/\.tar$//'`&quot; debug INFO serving tarred dir &quot;$dir&quot; echo 'Content-type: application/x-tar' echo tar -c &quot;$dir&quot; } function process { local url=&quot;`awk '{print $2}' | head -n 1`&quot; case &quot;$url&quot; in /) debug INFO Processing &quot;$url&quot; as dir serve_dir &quot;$url&quot; break ;; *) debug INFO Processing &quot;$url&quot; as file serve_file &quot;$url&quot; ;; esac } function serve { local port=&quot;$1&quot; local sin=&quot;$2&quot; local sout=&quot;$3&quot; while debug INFO Running nc; do nc -l -p &quot;$port&quot; &lt; &quot;$sin&quot; &gt; &quot;$sout&quot; &amp; pid=&quot;$!&quot; debug INFO Server PID: &quot;$pid&quot; trap cleanup SIGINT head -n 1 &quot;$sout&quot; | process &gt; &quot;$sin&quot; trap - SIGINT debug INFO Killing nc kill &quot;$pid&quot; done debug INFO Quiting server } function cleanup { debug INFO Caught signal, quitting... rm -Rf &quot;$tmp_dir&quot; exit } tmp_dir=&quot;`mktemp -d -t http_server.XXXXXXXXXX`&quot; sin=&quot;$tmp_dir&quot;/in sout=&quot;$tmp_dir&quot;/out pid=0 port=&quot;$1&quot; mkfifo &quot;$sin&quot; mkfifo &quot;$sout&quot; debug INFO Starting server on port &quot;$port&quot; serve &quot;$port&quot; &quot;$sin&quot; &quot;$sout&quot;</code> </pre></div> </div> </div> </div> <p>by <span class="printuser avatarhover"><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank"><img class="small" src="http://www.wikidot.com/avatar.php?userid=2462&amp;size=small&amp;timestamp=1328999362" alt="Gabrys" style="background-image:url(http://www.wikidot.com/userkarma.php?u=2462)" /></a><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank">Gabrys</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://piotr.gabryjeluk.pl/dev:running-things-in-parallel-in-bash</guid>
				<title>Running things in parallel in BASH</title>
				<link>http://piotr.gabryjeluk.pl/dev:running-things-in-parallel-in-bash</link>
				<description>

&lt;p&gt;Suppose you have a nice script that does its job pretty well, but you figured out, that running certain parts of scripts in parallel would speed things up.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=2462&amp;amp;size=small&amp;amp;timestamp=1328999362&quot; alt=&quot;Gabrys&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=2462)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;Gabrys&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Mon, 09 Mar 2009 00:21:22 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Suppose you have a nice script that does its job pretty well, but you figured out, that running certain parts of scripts in parallel would speed things up.</p> <div class="content-separator" style="display: none:"></div> <p>This can be the option, when you send a bunch of files to an Internet service, that is generally fast, but the connection sequence is quite slow, so uploading 100 files one after one causes the script to wait 100 times to quickly upload a file.</p> <p>Other situation could be when you have multi-core machine, for example you have eight processing units, but use only one in your script, and you have a bunch of files to compile or to process in some CPU-expensive manner.</p> <p>We'll use only BASH to smartly parallelize the tasks and speed up the slow part of your script.</p> <p>First of all you need to know how many jobs in parallel you want (if you have 8 cores and CPU-expensive part of script, having more than 8 jobs does not help, probably a number between 4 and 8 will do best in this case).</p> <div class="code"> <pre> <code>#!/bin/bash PROC_NUM=4</code> </pre></div> <p>Generally, we'll ensure, than no more than <tt>PROC_NUM</tt> processes are forked into background and run another task. If there are <tt>PROC_NUM</tt> processes running in the background we'll wait a (fraction of) second and check again.</p> <div class="code"> <pre> <code>#!/bin/bash PROC_NUM=4 function run_task() { # task to run # can be more than one-line # can take parameters $1, $2, ... } function run_parallel() { while [ `jobs | grep Running | wc -l` -ge $PROC_NUM ]; do sleep 0.25 done run_task &quot;$@&quot; &amp; }</code> </pre></div> <p><tt>run_task &quot;$@&quot;</tt> passes all the parameters passed to run_parallel to run_task. You can use <tt>&quot;$@&quot;</tt> in run_task to pass all the parameters to external command! The <tt>&quot;$@&quot;</tt> is the best choice when you have spaces, dollars and other special characters in parameters. It doesn't transform anything, it's completely safe (probably the only short way to pass all the parameters).</p> <p>There are only two things left: invoking the <tt>run_parallel</tt> and synchronizing the tasks &#8212; you need to know when ALL the tasks ended, right?</p> <div class="code"> <pre> <code>#!/bin/bash PROC_NUM=4 function run_task() { # task to run # can be more than one-line # can take parameters $1, $2, ... } function run_parallel() { while [ `jobs | grep Running | wc -l` -ge $PROC_NUM ]; do sleep 0.25 done run_task &quot;$@&quot; &amp; } function end_parallel() { while [ `jobs | grep Running | wc -l` -gt 0 ]; do sleep 0.25 done } # script content cd /some/where/you/want # now the parallel operations # for example in some while find | while read file; do run_parallel &quot;$file&quot; done # now you want to continue when ALL parallel tasks ended end_parallel # the linear script code again cd /some/where/else make something</code> </pre></div> <p>That's all! Though, there is a different approach to this:</p> <div class="code"> <pre> <code>#!/bin/bash function parallel() { local PROC_NUM=&quot;$1&quot; local SLEEP_TIME=&quot;$2&quot; shift; shift while [ `jobs | grep Running | wc -l` -ge $PROC_NUM ]; do sleep $SLEEP_TIME done &quot;$@&quot; &amp; }</code> </pre></div> <p>This function acts as a wrapper to a non-parallel command and runs it in the background assuring that no more than <tt>PROC_NUM</tt> processes run at once. If there are <tt>PROC_NUM</tt> processes running in the background, the wrapper waits <tt>SLEEP_TIME</tt> to re-check the number of background jobs.</p> <p>Invoking:</p> <div class="code"> <pre> <code>parallel PROC_NUM SLEEP_TIME /usr/bin/some-command arguments ...</code> </pre></div> <p>so</p> <div class="code"> <pre> <code>parallel 4 0.5 ls -R /tmp</code> </pre></div> <p>means: run <tt>ls -R /tmp</tt> in the background if there is no more than 3 processes already run in the background. Otherwise wait 0.5 seconds and try again. Then run <tt>ls -R /tmp</tt> if there is no more than 3 processes already run in the background. Otherwise wait 0.5 seconds and try again. Then run <tt>ls -R /tmp</tt> if &#8230;</p> <p>Quite nice, isn't it?</p> <p>by <span class="printuser avatarhover"><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank"><img class="small" src="http://www.wikidot.com/avatar.php?userid=2462&amp;size=small&amp;timestamp=1328999362" alt="Gabrys" style="background-image:url(http://www.wikidot.com/userkarma.php?u=2462)" /></a><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank">Gabrys</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://piotr.gabryjeluk.pl/dev:nice-bash-random-implementation</guid>
				<title>Nice BASH Random Implementation</title>
				<link>http://piotr.gabryjeluk.pl/dev:nice-bash-random-implementation</link>
				<description>

&lt;p&gt;Today I wrote something like this in BASH:&lt;/p&gt;
&lt;div class=&quot;code&quot;&gt;
&lt;pre&gt;
&lt;code&gt;echo $(($(printf &#039;%d&#039; &amp;quot;&#039;`head -c 1 /dev/urandom | base64 | tr A D`&amp;quot;)%4))&lt;/code&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=2462&amp;amp;size=small&amp;amp;timestamp=1328999363&quot; alt=&quot;Gabrys&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=2462)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;Gabrys&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Thu, 05 Mar 2009 20:20:28 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Today I wrote something like this in BASH:</p> <div class="code"> <pre> <code>echo $(($(printf '%d' &quot;'`head -c 1 /dev/urandom | base64 | tr A D`&quot;)%4))</code> </pre></div> <div class="content-separator" style="display: none:"></div> <p>This prints a random number from 0 to 3. How it works?</p> <p>Firstly the command below prints one random byte using special Unix /dev/urandom device:</p> <div class="code"> <pre> <code>head -c 1 /dev/urandom</code> </pre></div> <p>Piping this to <tt>| base64</tt> gives us base64 representation of the byte.</p> <p><a href="http://en.wikipedia.org/wiki/Base64" >Base64</a> is a method of encoding 8-bit data as human-readable strings using only 64 visible characters (letters, digits and some !@ and stuff). Whitespace is always ignored when reading base64 string. The standard is really nice, because you can for example read a base64-encoded file with a phone or send a printout of it with a classic mail. Because all the characters are human-readable, one can enter them and decode the original message. The format is used widely for sending emails.</p> <p>It is important for us, that running base64 on a random byte gives us 2 bytes that are only &quot;normal&quot; characters, ie don't have any special meaning in any context (like some white characters may have).</p> <p>Now comes the tricky part:</p> <div class="code"> <pre> <code>printf '%d' &quot;'`head -c 1 /dev/urandom | base64`&quot;</code> </pre></div> <p><tt>printf '%d' &quot;'a&quot;</tt> would give us 97 &#8212; this is the ASCII code of letter a. Remember we get two bytes of data after base64? No problem, printf cares in this case only about the first character.</p> <p>As you may notice the output of this is one of these:</p> <ul> <li>43</li> <li>a number between 47 and 57</li> <li>a number between 65 and 90</li> <li>a number between 97 and 122</li> </ul> <p>This gives us 64 possibilities. Great! 6 bits is just the same as 64.</p> <p>This is when we get to BASH arithmetics. This is how it works:</p> <div class="code"> <pre> <code>echo $((7*12))</code> </pre></div> <p>This should print 84 obviously. Knowing that enclosing a string in <tt>$(</tt> and <tt>)</tt> causes BASH to run the enclosed command and return its results (just like using the backticks: `command`) this is everything.</p> <p>The % means modulo in BASH arithmetic (just like in C, Java, Python, PHP, &#8230;), so this:</p> <div class="code"> <pre> <code>echo $(($(printf '%d' &quot;'`head -c 1 /dev/urandom | base64`&quot;)%4))</code> </pre></div> <p>prints the number we generated (one of 43, 47&#8230;57, 65&#8230;90, 97&#8230;122) modulo 4. This needs to be 0, 1, 2 or 3.</p> <p>Let's now check what the probability of receiving each of the digits.</p> <p>Suppose /dev/urandom prints every possible byte with equal probability. We'll now analyze each byte (possibly) generated by /dev/urandom, it's base64 representation, ASCII code of first byte of the representation and the modulo 4 of it. We'll use a table for it:</p> <table class="wiki-content-table"> <tr> <th>/dev/urandom byte</th> <th>base64</th> <th>code of the first letter of base64</th> <th>the same modulo 4</th> </tr> <tr> <td>(code 0)</td> <td>AA==</td> <td>65</td> <td>1</td> </tr> <tr> <td>(code 1)</td> <td>AQ==</td> <td>65</td> <td>1</td> </tr> <tr> <td>(code 2)</td> <td>Ag==</td> <td>65</td> <td>1</td> </tr> <tr> <td>(code 3)</td> <td>Aw==</td> <td>65</td> <td>1</td> </tr> <tr> <td>(code 4)</td> <td>BA==</td> <td>66</td> <td>2</td> </tr> <tr> <td>(code 5)</td> <td>BQ==</td> <td>66</td> <td>2</td> </tr> <tr> <td>(code 6)</td> <td>Bg==</td> <td>66</td> <td>2</td> </tr> <tr> <td>(code 7)</td> <td>Bw==</td> <td>66</td> <td>2</td> </tr> <tr> <td>(code 8)</td> <td>CA==</td> <td>67</td> <td>3</td> </tr> <tr> <td>(code 9)</td> <td>CQ==</td> <td>67</td> <td>3</td> </tr> <tr> <td>(code 10)</td> <td>Cg==</td> <td>67</td> <td>3</td> </tr> <tr> <td>(code 11)</td> <td>Cw==</td> <td>67</td> <td>3</td> </tr> <tr> <td>(code 12)</td> <td>DA==</td> <td>68</td> <td>0</td> </tr> <tr> <td>(code 13)</td> <td>DQ==</td> <td>68</td> <td>0</td> </tr> <tr> <td>(␌⎺␍␊ 14)</td> <td>Dg==</td> <td>68</td> <td>0</td> </tr> <tr> <td>(code 15)</td> <td>Dw==</td> <td>68</td> <td>0</td> </tr> <tr> <td>(code 16)</td> <td>EA==</td> <td>69</td> <td>1</td> </tr> <tr> <td>(code 17)</td> <td>EQ==</td> <td>69</td> <td>1</td> </tr> <tr> <td>(code 18)</td> <td>Eg==</td> <td>69</td> <td>1</td> </tr> <tr> <td>(code 19)</td> <td>Ew==</td> <td>69</td> <td>1</td> </tr> <tr> <td>(code 20)</td> <td>FA==</td> <td>70</td> <td>2</td> </tr> <tr> <td>(code 21)</td> <td>FQ==</td> <td>70</td> <td>2</td> </tr> <tr> <td>(code 22)</td> <td>Fg==</td> <td>70</td> <td>2</td> </tr> <tr> <td>(code 23)</td> <td>Fw==</td> <td>70</td> <td>2</td> </tr> <tr> <td>(code 24)</td> <td>GA==</td> <td>71</td> <td>3</td> </tr> <tr> <td>(code 25)</td> <td>GQ==</td> <td>71</td> <td>3</td> </tr> <tr> <td>(code 26)</td> <td>Gg==</td> <td>71</td> <td>3</td> </tr> <tr> <td>(code 27)</td> <td>Gw==</td> <td>71</td> <td>3</td> </tr> <tr> <td>(code 28)</td> <td>HA==</td> <td>72</td> <td>0</td> </tr> <tr> <td>(code 29)</td> <td>HQ==</td> <td>72</td> <td>0</td> </tr> <tr> <td>(code 30)</td> <td>Hg==</td> <td>72</td> <td>0</td> </tr> <tr> <td>(code 31)</td> <td>Hw==</td> <td>72</td> <td>0</td> </tr> <tr> <td>(code 32)</td> <td>IA==</td> <td>73</td> <td>1</td> </tr> <tr> <td>! (code 33)</td> <td>IQ==</td> <td>73</td> <td>1</td> </tr> <tr> <td>&quot; (code 34)</td> <td>Ig==</td> <td>73</td> <td>1</td> </tr> <tr> <td># (code 35)</td> <td>Iw==</td> <td>73</td> <td>1</td> </tr> <tr> <td>$ (code 36)</td> <td>JA==</td> <td>74</td> <td>2</td> </tr> <tr> <td>% (code 37)</td> <td>JQ==</td> <td>74</td> <td>2</td> </tr> <tr> <td>&amp; (code 38)</td> <td>Jg==</td> <td>74</td> <td>2</td> </tr> <tr> <td>' (code 39)</td> <td>Jw==</td> <td>74</td> <td>2</td> </tr> <tr> <td>( (code 40)</td> <td>KA==</td> <td>75</td> <td>3</td> </tr> <tr> <td>) (code 41)</td> <td>KQ==</td> <td>75</td> <td>3</td> </tr> <tr> <td>* (code 42)</td> <td>Kg==</td> <td>75</td> <td>3</td> </tr> <tr> <td>+ (code 43)</td> <td>Kw==</td> <td>75</td> <td>3</td> </tr> <tr> <td>, (code 44)</td> <td>LA==</td> <td>76</td> <td>0</td> </tr> <tr> <td>- (code 45)</td> <td>LQ==</td> <td>76</td> <td>0</td> </tr> <tr> <td>. (code 46)</td> <td>Lg==</td> <td>76</td> <td>0</td> </tr> <tr> <td>/ (code 47)</td> <td>Lw==</td> <td>76</td> <td>0</td> </tr> <tr> <td>0 (code 48)</td> <td>MA==</td> <td>77</td> <td>1</td> </tr> <tr> <td>1 (code 49)</td> <td>MQ==</td> <td>77</td> <td>1</td> </tr> <tr> <td>2 (code 50)</td> <td>Mg==</td> <td>77</td> <td>1</td> </tr> <tr> <td>3 (code 51)</td> <td>Mw==</td> <td>77</td> <td>1</td> </tr> <tr> <td>4 (code 52)</td> <td>NA==</td> <td>78</td> <td>2</td> </tr> <tr> <td>5 (code 53)</td> <td>NQ==</td> <td>78</td> <td>2</td> </tr> <tr> <td>6 (code 54)</td> <td>Ng==</td> <td>78</td> <td>2</td> </tr> <tr> <td>7 (code 55)</td> <td>Nw==</td> <td>78</td> <td>2</td> </tr> <tr> <td>8 (code 56)</td> <td>OA==</td> <td>79</td> <td>3</td> </tr> <tr> <td>9 (code 57)</td> <td>OQ==</td> <td>79</td> <td>3</td> </tr> <tr> <td>: (code 58)</td> <td>Og==</td> <td>79</td> <td>3</td> </tr> <tr> <td>; (code 59)</td> <td>Ow==</td> <td>79</td> <td>3</td> </tr> <tr> <td>&lt; (code 60)</td> <td>PA==</td> <td>80</td> <td>0</td> </tr> <tr> <td>= (code 61)</td> <td>PQ==</td> <td>80</td> <td>0</td> </tr> <tr> <td>&gt; (code 62)</td> <td>Pg==</td> <td>80</td> <td>0</td> </tr> <tr> <td>? (code 63)</td> <td>Pw==</td> <td>80</td> <td>0</td> </tr> <tr> <td>@ (code 64)</td> <td>QA==</td> <td>81</td> <td>1</td> </tr> <tr> <td>A (code 65)</td> <td>QQ==</td> <td>81</td> <td>1</td> </tr> <tr> <td>B (code 66)</td> <td>Qg==</td> <td>81</td> <td>1</td> </tr> <tr> <td>C (code 67)</td> <td>Qw==</td> <td>81</td> <td>1</td> </tr> <tr> <td>D (code 68)</td> <td>RA==</td> <td>82</td> <td>2</td> </tr> <tr> <td>E (code 69)</td> <td>RQ==</td> <td>82</td> <td>2</td> </tr> <tr> <td>F (code 70)</td> <td>Rg==</td> <td>82</td> <td>2</td> </tr> <tr> <td>G (code 71)</td> <td>Rw==</td> <td>82</td> <td>2</td> </tr> <tr> <td>H (code 72)</td> <td>SA==</td> <td>83</td> <td>3</td> </tr> <tr> <td>I (code 73)</td> <td>SQ==</td> <td>83</td> <td>3</td> </tr> <tr> <td>J (code 74)</td> <td>Sg==</td> <td>83</td> <td>3</td> </tr> <tr> <td>K (code 75)</td> <td>Sw==</td> <td>83</td> <td>3</td> </tr> <tr> <td>L (code 76)</td> <td>TA==</td> <td>84</td> <td>0</td> </tr> <tr> <td>M (code 77)</td> <td>TQ==</td> <td>84</td> <td>0</td> </tr> <tr> <td>N (code 78)</td> <td>Tg==</td> <td>84</td> <td>0</td> </tr> <tr> <td>O (code 79)</td> <td>Tw==</td> <td>84</td> <td>0</td> </tr> <tr> <td>P (code 80)</td> <td>UA==</td> <td>85</td> <td>1</td> </tr> <tr> <td>Q (code 81)</td> <td>UQ==</td> <td>85</td> <td>1</td> </tr> <tr> <td>R (code 82)</td> <td>Ug==</td> <td>85</td> <td>1</td> </tr> <tr> <td>S (code 83)</td> <td>Uw==</td> <td>85</td> <td>1</td> </tr> <tr> <td>T (code 84)</td> <td>VA==</td> <td>86</td> <td>2</td> </tr> <tr> <td>U (code 85)</td> <td>VQ==</td> <td>86</td> <td>2</td> </tr> <tr> <td>V (code 86)</td> <td>Vg==</td> <td>86</td> <td>2</td> </tr> <tr> <td>W (code 87)</td> <td>Vw==</td> <td>86</td> <td>2</td> </tr> <tr> <td>X (code 88)</td> <td>WA==</td> <td>87</td> <td>3</td> </tr> <tr> <td>Y (code 89)</td> <td>WQ==</td> <td>87</td> <td>3</td> </tr> <tr> <td>Z (code 90)</td> <td>Wg==</td> <td>87</td> <td>3</td> </tr> <tr> <td>[ (code 91)</td> <td>Ww==</td> <td>87</td> <td>3</td> </tr> <tr> <td>\ (code 92)</td> <td>XA==</td> <td>88</td> <td>0</td> </tr> <tr> <td>] (code 93)</td> <td>XQ==</td> <td>88</td> <td>0</td> </tr> <tr> <td>^ (code 94)</td> <td>Xg==</td> <td>88</td> <td>0</td> </tr> <tr> <td>_ (code 95)</td> <td>Xw==</td> <td>88</td> <td>0</td> </tr> <tr> <td>` (code 96)</td> <td>YA==</td> <td>89</td> <td>1</td> </tr> <tr> <td>a (code 97)</td> <td>YQ==</td> <td>89</td> <td>1</td> </tr> <tr> <td>b (code 98)</td> <td>Yg==</td> <td>89</td> <td>1</td> </tr> <tr> <td>c (code 99)</td> <td>Yw==</td> <td>89</td> <td>1</td> </tr> <tr> <td>d (code 100)</td> <td>ZA==</td> <td>90</td> <td>2</td> </tr> <tr> <td>e (code 101)</td> <td>ZQ==</td> <td>90</td> <td>2</td> </tr> <tr> <td>f (code 102)</td> <td>Zg==</td> <td>90</td> <td>2</td> </tr> <tr> <td>g (code 103)</td> <td>Zw==</td> <td>90</td> <td>2</td> </tr> <tr> <td>h (code 104)</td> <td>aA==</td> <td>97</td> <td>1</td> </tr> <tr> <td>i (code 105)</td> <td>aQ==</td> <td>97</td> <td>1</td> </tr> <tr> <td>j (code 106)</td> <td>ag==</td> <td>97</td> <td>1</td> </tr> <tr> <td>k (code 107)</td> <td>aw==</td> <td>97</td> <td>1</td> </tr> <tr> <td>l (code 108)</td> <td>bA==</td> <td>98</td> <td>2</td> </tr> <tr> <td>m (code 109)</td> <td>bQ==</td> <td>98</td> <td>2</td> </tr> <tr> <td>n (code 110)</td> <td>bg==</td> <td>98</td> <td>2</td> </tr> <tr> <td>o (code 111)</td> <td>bw==</td> <td>98</td> <td>2</td> </tr> <tr> <td>p (code 112)</td> <td>cA==</td> <td>99</td> <td>3</td> </tr> <tr> <td>q (code 113)</td> <td>cQ==</td> <td>99</td> <td>3</td> </tr> <tr> <td>r (code 114)</td> <td>cg==</td> <td>99</td> <td>3</td> </tr> <tr> <td>s (code 115)</td> <td>cw==</td> <td>99</td> <td>3</td> </tr> <tr> <td>t (code 116)</td> <td>dA==</td> <td>100</td> <td>0</td> </tr> <tr> <td>u (code 117)</td> <td>dQ==</td> <td>100</td> <td>0</td> </tr> <tr> <td>v (code 118)</td> <td>dg==</td> <td>100</td> <td>0</td> </tr> <tr> <td>w (code 119)</td> <td>dw==</td> <td>100</td> <td>0</td> </tr> <tr> <td>x (code 120)</td> <td>eA==</td> <td>101</td> <td>1</td> </tr> <tr> <td>y (code 121)</td> <td>eQ==</td> <td>101</td> <td>1</td> </tr> <tr> <td>z (code 122)</td> <td>eg==</td> <td>101</td> <td>1</td> </tr> <tr> <td>{ (code 123)</td> <td>ew==</td> <td>101</td> <td>1</td> </tr> <tr> <td>| (code 124)</td> <td>fA==</td> <td>102</td> <td>2</td> </tr> <tr> <td>} (code 125)</td> <td>fQ==</td> <td>102</td> <td>2</td> </tr> <tr> <td>~ (code 126)</td> <td>fg==</td> <td>102</td> <td>2</td> </tr> <tr> <td> (code 127)</td> <td>fw==</td> <td>102</td> <td>2</td> </tr> <tr> <td>� (code 128)</td> <td>gA==</td> <td>103</td> <td>3</td> </tr> <tr> <td>� (code 129)</td> <td>gQ==</td> <td>103</td> <td>3</td> </tr> <tr> <td>� (code 130)</td> <td>gg==</td> <td>103</td> <td>3</td> </tr> <tr> <td>� (code 131)</td> <td>gw==</td> <td>103</td> <td>3</td> </tr> <tr> <td>� (code 132)</td> <td>hA==</td> <td>104</td> <td>0</td> </tr> <tr> <td>� (code 133)</td> <td>hQ==</td> <td>104</td> <td>0</td> </tr> <tr> <td>� (code 134)</td> <td>hg==</td> <td>104</td> <td>0</td> </tr> <tr> <td>� (code 135)</td> <td>hw==</td> <td>104</td> <td>0</td> </tr> <tr> <td>� (code 136)</td> <td>iA==</td> <td>105</td> <td>1</td> </tr> <tr> <td>� (code 137)</td> <td>iQ==</td> <td>105</td> <td>1</td> </tr> <tr> <td>� (code 138)</td> <td>ig==</td> <td>105</td> <td>1</td> </tr> <tr> <td>� (code 139)</td> <td>iw==</td> <td>105</td> <td>1</td> </tr> <tr> <td>� (code 140)</td> <td>jA==</td> <td>106</td> <td>2</td> </tr> <tr> <td>� (code 141)</td> <td>jQ==</td> <td>106</td> <td>2</td> </tr> <tr> <td>(code 142)</td> <td>jg==</td> <td>106</td> <td>2</td> </tr> <tr> <td>(code 143)</td> <td>jw==</td> <td>106</td> <td>2</td> </tr> <tr> <td>� (code 144)</td> <td>kA==</td> <td>107</td> <td>3</td> </tr> <tr> <td>� (code 145)</td> <td>kQ==</td> <td>107</td> <td>3</td> </tr> <tr> <td>� (code 146)</td> <td>kg==</td> <td>107</td> <td>3</td> </tr> <tr> <td>� (code 147)</td> <td>kw==</td> <td>107</td> <td>3</td> </tr> <tr> <td>� (code 148)</td> <td>lA==</td> <td>108</td> <td>0</td> </tr> <tr> <td>� (code 149)</td> <td>lQ==</td> <td>108</td> <td>0</td> </tr> <tr> <td>� (code 150)</td> <td>lg==</td> <td>108</td> <td>0</td> </tr> <tr> <td>� (code 151)</td> <td>lw==</td> <td>108</td> <td>0</td> </tr> <tr> <td>� (code 152)</td> <td>mA==</td> <td>109</td> <td>1</td> </tr> <tr> <td>� (code 153)</td> <td>mQ==</td> <td>109</td> <td>1</td> </tr> <tr> <td>� (code 154)</td> <td>mg==</td> <td>109</td> <td>1</td> </tr> <tr> <td>� (code 155)</td> <td>mw==</td> <td>109</td> <td>1</td> </tr> <tr> <td>� (code 156)</td> <td>nA==</td> <td>110</td> <td>2</td> </tr> <tr> <td>� (code 157)</td> <td>nQ==</td> <td>110</td> <td>2</td> </tr> <tr> <td>� (code 158)</td> <td>ng==</td> <td>110</td> <td>2</td> </tr> <tr> <td>� (code 159)</td> <td>nw==</td> <td>110</td> <td>2</td> </tr> <tr> <td>� (code 160)</td> <td>oA==</td> <td>111</td> <td>3</td> </tr> <tr> <td>� (code 161)</td> <td>oQ==</td> <td>111</td> <td>3</td> </tr> <tr> <td>� (code 162)</td> <td>og==</td> <td>111</td> <td>3</td> </tr> <tr> <td>� (code 163)</td> <td>ow==</td> <td>111</td> <td>3</td> </tr> <tr> <td>� (code 164)</td> <td>pA==</td> <td>112</td> <td>0</td> </tr> <tr> <td>� (code 165)</td> <td>pQ==</td> <td>112</td> <td>0</td> </tr> <tr> <td>� (code 166)</td> <td>pg==</td> <td>112</td> <td>0</td> </tr> <tr> <td>� (code 167)</td> <td>pw==</td> <td>112</td> <td>0</td> </tr> <tr> <td>� (code 168)</td> <td>qA==</td> <td>113</td> <td>1</td> </tr> <tr> <td>� (code 169)</td> <td>qQ==</td> <td>113</td> <td>1</td> </tr> <tr> <td>� (code 170)</td> <td>qg==</td> <td>113</td> <td>1</td> </tr> <tr> <td>� (code 171)</td> <td>qw==</td> <td>113</td> <td>1</td> </tr> <tr> <td>� (code 172)</td> <td>rA==</td> <td>114</td> <td>2</td> </tr> <tr> <td>� (code 173)</td> <td>rQ==</td> <td>114</td> <td>2</td> </tr> <tr> <td>� (code 174)</td> <td>rg==</td> <td>114</td> <td>2</td> </tr> <tr> <td>� (code 175)</td> <td>rw==</td> <td>114</td> <td>2</td> </tr> <tr> <td>� (code 176)</td> <td>sA==</td> <td>115</td> <td>3</td> </tr> <tr> <td>� (code 177)</td> <td>sQ==</td> <td>115</td> <td>3</td> </tr> <tr> <td>� (code 178)</td> <td>sg==</td> <td>115</td> <td>3</td> </tr> <tr> <td>� (code 179)</td> <td>sw==</td> <td>115</td> <td>3</td> </tr> <tr> <td>� (code 180)</td> <td>tA==</td> <td>116</td> <td>0</td> </tr> <tr> <td>� (code 181)</td> <td>tQ==</td> <td>116</td> <td>0</td> </tr> <tr> <td>� (code 182)</td> <td>tg==</td> <td>116</td> <td>0</td> </tr> <tr> <td>� (code 183)</td> <td>tw==</td> <td>116</td> <td>0</td> </tr> <tr> <td>� (code 184)</td> <td>uA==</td> <td>117</td> <td>1</td> </tr> <tr> <td>� (code 185)</td> <td>uQ==</td> <td>117</td> <td>1</td> </tr> <tr> <td>� (code 186)</td> <td>ug==</td> <td>117</td> <td>1</td> </tr> <tr> <td>� (code 187)</td> <td>uw==</td> <td>117</td> <td>1</td> </tr> <tr> <td>� (code 188)</td> <td>vA==</td> <td>118</td> <td>2</td> </tr> <tr> <td>� (code 189)</td> <td>vQ==</td> <td>118</td> <td>2</td> </tr> <tr> <td>� (code 190)</td> <td>vg==</td> <td>118</td> <td>2</td> </tr> <tr> <td>� (code 191)</td> <td>vw==</td> <td>118</td> <td>2</td> </tr> <tr> <td>� (code 192)</td> <td>wA==</td> <td>119</td> <td>3</td> </tr> <tr> <td>� (code 193)</td> <td>wQ==</td> <td>119</td> <td>3</td> </tr> <tr> <td>� (code 194)</td> <td>wg==</td> <td>119</td> <td>3</td> </tr> <tr> <td>� (code 195)</td> <td>ww==</td> <td>119</td> <td>3</td> </tr> <tr> <td>� (code 196)</td> <td>xA==</td> <td>120</td> <td>0</td> </tr> <tr> <td>� (code 197)</td> <td>xQ==</td> <td>120</td> <td>0</td> </tr> <tr> <td>� (code 198)</td> <td>xg==</td> <td>120</td> <td>0</td> </tr> <tr> <td>� (code 199)</td> <td>xw==</td> <td>120</td> <td>0</td> </tr> <tr> <td>� (code 200)</td> <td>yA==</td> <td>121</td> <td>1</td> </tr> <tr> <td>� (code 201)</td> <td>yQ==</td> <td>121</td> <td>1</td> </tr> <tr> <td>� (code 202)</td> <td>yg==</td> <td>121</td> <td>1</td> </tr> <tr> <td>� (code 203)</td> <td>yw==</td> <td>121</td> <td>1</td> </tr> <tr> <td>� (code 204)</td> <td>zA==</td> <td>122</td> <td>2</td> </tr> <tr> <td>� (code 205)</td> <td>zQ==</td> <td>122</td> <td>2</td> </tr> <tr> <td>� (code 206)</td> <td>zg==</td> <td>122</td> <td>2</td> </tr> <tr> <td>� (code 207)</td> <td>zw==</td> <td>122</td> <td>2</td> </tr> <tr> <td>� (code 208)</td> <td>0A==</td> <td>48</td> <td>0</td> </tr> <tr> <td>� (code 209)</td> <td>0Q==</td> <td>48</td> <td>0</td> </tr> <tr> <td>� (code 210)</td> <td>0g==</td> <td>48</td> <td>0</td> </tr> <tr> <td>� (code 211)</td> <td>0w==</td> <td>48</td> <td>0</td> </tr> <tr> <td>� (code 212)</td> <td>1A==</td> <td>49</td> <td>1</td> </tr> <tr> <td>� (code 213)</td> <td>1Q==</td> <td>49</td> <td>1</td> </tr> <tr> <td>� (code 214)</td> <td>1g==</td> <td>49</td> <td>1</td> </tr> <tr> <td>� (code 215)</td> <td>1w==</td> <td>49</td> <td>1</td> </tr> <tr> <td>� (code 216)</td> <td>2A==</td> <td>50</td> <td>2</td> </tr> <tr> <td>� (code 217)</td> <td>2Q==</td> <td>50</td> <td>2</td> </tr> <tr> <td>� (code 218)</td> <td>2g==</td> <td>50</td> <td>2</td> </tr> <tr> <td>� (code 219)</td> <td>2w==</td> <td>50</td> <td>2</td> </tr> <tr> <td>� (code 220)</td> <td>3A==</td> <td>51</td> <td>3</td> </tr> <tr> <td>� (code 221)</td> <td>3Q==</td> <td>51</td> <td>3</td> </tr> <tr> <td>� (code 222)</td> <td>3g==</td> <td>51</td> <td>3</td> </tr> <tr> <td>� (code 223)</td> <td>3w==</td> <td>51</td> <td>3</td> </tr> <tr> <td>� (code 224)</td> <td>4A==</td> <td>52</td> <td>0</td> </tr> <tr> <td>� (code 225)</td> <td>4Q==</td> <td>52</td> <td>0</td> </tr> <tr> <td>� (code 226)</td> <td>4g==</td> <td>52</td> <td>0</td> </tr> <tr> <td>� (code 227)</td> <td>4w==</td> <td>52</td> <td>0</td> </tr> <tr> <td>� (code 228)</td> <td>5A==</td> <td>53</td> <td>1</td> </tr> <tr> <td>� (code 229)</td> <td>5Q==</td> <td>53</td> <td>1</td> </tr> <tr> <td>� (code 230)</td> <td>5g==</td> <td>53</td> <td>1</td> </tr> <tr> <td>� (code 231)</td> <td>5w==</td> <td>53</td> <td>1</td> </tr> <tr> <td>� (code 232)</td> <td>6A==</td> <td>54</td> <td>2</td> </tr> <tr> <td>� (code 233)</td> <td>6Q==</td> <td>54</td> <td>2</td> </tr> <tr> <td>� (code 234)</td> <td>6g==</td> <td>54</td> <td>2</td> </tr> <tr> <td>� (code 235)</td> <td>6w==</td> <td>54</td> <td>2</td> </tr> <tr> <td>� (code 236)</td> <td>7A==</td> <td>55</td> <td>3</td> </tr> <tr> <td>� (code 237)</td> <td>7Q==</td> <td>55</td> <td>3</td> </tr> <tr> <td>� (code 238)</td> <td>7g==</td> <td>55</td> <td>3</td> </tr> <tr> <td>� (code 239)</td> <td>7w==</td> <td>55</td> <td>3</td> </tr> <tr> <td>� (code 240)</td> <td>8A==</td> <td>56</td> <td>0</td> </tr> <tr> <td>� (code 241)</td> <td>8Q==</td> <td>56</td> <td>0</td> </tr> <tr> <td>� (code 242)</td> <td>8g==</td> <td>56</td> <td>0</td> </tr> <tr> <td>� (code 243)</td> <td>8w==</td> <td>56</td> <td>0</td> </tr> <tr> <td>� (code 244)</td> <td>9A==</td> <td>57</td> <td>1</td> </tr> <tr> <td>� (code 245)</td> <td>9Q==</td> <td>57</td> <td>1</td> </tr> <tr> <td>� (code 246)</td> <td>9g==</td> <td>57</td> <td>1</td> </tr> <tr> <td>� (code 247)</td> <td>9w==</td> <td>57</td> <td>1</td> </tr> <tr> <td>� (code 248)</td> <td>+A==</td> <td>43</td> <td>3</td> </tr> <tr> <td>� (code 249)</td> <td>+Q==</td> <td>43</td> <td>3</td> </tr> <tr> <td>� (code 250)</td> <td>+g==</td> <td>43</td> <td>3</td> </tr> <tr> <td>� (code 251)</td> <td>+w==</td> <td>43</td> <td>3</td> </tr> <tr> <td>� (code 252)</td> <td>/A==</td> <td>47</td> <td>3</td> </tr> <tr> <td>� (code 253)</td> <td>/Q==</td> <td>47</td> <td>3</td> </tr> <tr> <td>� (code 254)</td> <td>/g==</td> <td>47</td> <td>3</td> </tr> <tr> <td>� (code 255)</td> <td>/w==</td> <td>47</td> <td>3</td> </tr> </table> <p>(Some of the symbols in the first column may appear not visible or otherwise look strange. This is normal, there are many characters in ASCII that has (or had) some special meaning.)</p> <p>Let's count have many 0s, 1s, 2s and 3s did we get:</p> <table class="wiki-content-table"> <tr> <td>0</td> <td>60</td> </tr> <tr> <td>1</td> <td>68</td> </tr> <tr> <td>2</td> <td>64</td> </tr> <tr> <td>3</td> <td>64</td> </tr> </table> <p>This is not ideal, because you get statistically slightly more 1s than 0s, but if you don't care too much, this is all!</p> <p>If you care however, here is some solution. We need to get 4 results that give us 1 and convert them to some that gives 0:</p> <div class="code"> <pre> <code>echo $(($(printf '%d' &quot;'`head -c 1 /dev/urandom | base64 | tr A D`&quot;)%4))</code> </pre></div> <p>Notice the <tt>tr A D</tt>. This changes each A to D in the base64 output. Thus four rows of table above (for 0 to 4 codes) should behave like the 12 to 15 codes, thus giving 0 at the end instead of 1.</p> <p>We're done. Let's enclose the procedure in function clause and create a sample code that tells us how many 0s, 1s, 2s and 3s where hit within 100 shots.</p> <div class="code"> <pre> <code>#!/bin/bash function random() { echo $(($(printf '%d' &quot;'`head -c 1 /dev/urandom | base64 | tr A D`&quot;)%4)) } ret=`i=0; time while [ $i -lt 100 ]; do random ; i=$((i+1)); done` echo -n '0: ' ; echo &quot;$ret&quot; | grep 0 | wc -l echo -n '1: ' ; echo &quot;$ret&quot; | grep 1 | wc -l echo -n '2: ' ; echo &quot;$ret&quot; | grep 2 | wc -l echo -n '3: ' ; echo &quot;$ret&quot; | grep 3 | wc -l</code> </pre></div> <p>The program also shows how much time did it take to generate the numbers. Adjust the 100 to your needs ;).</p> <p><strong>UPDATE:</strong> having this article posted on <a href="http://www.reddit.com/r/programming/comments/82gd1/nice_bash_random_implementation/">reddit programming</a> gave me actually much much better ways of doing a random function (see in <a href="#comments">comments</a>). Thank you for your replies!</p> <p>by <span class="printuser avatarhover"><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank"><img class="small" src="http://www.wikidot.com/avatar.php?userid=2462&amp;size=small&amp;timestamp=1328999363" alt="Gabrys" style="background-image:url(http://www.wikidot.com/userkarma.php?u=2462)" /></a><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank">Gabrys</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://piotr.gabryjeluk.pl/dev:po-devcampie</guid>
				<title>Po Devcampie</title>
				<link>http://piotr.gabryjeluk.pl/dev:po-devcampie</link>
				<description>

&lt;p&gt;Zdecydowałem, że mój blog musi być bardziej pozytywny.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=2462&amp;amp;size=small&amp;amp;timestamp=1328999363&quot; alt=&quot;Gabrys&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=2462)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://piotr.gabryjeluk.pl/profile2:2462&quot; target=&quot;_blank&quot;&gt;Gabrys&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 26 Oct 2008 15:59:46 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Zdecydowałem, że mój blog musi być bardziej pozytywny.</p> <p>Zatem, po pierwsze: iPhone rządzi, bo ma basha.</p> <p>Po drugie: devcamp rządził :]. Chłopaki z www.socjum.pl też są spoko i zapraszają do Krakowa na imprezę, jaką długo spamiętamy.</p> <p>Po trzecie: z pomocą Zająca odpaliłem na moim lapie Compiza w konfiguracji Dual Head na karcie graficznej Intela (a jak wszyscy wiedzą mam dwie karty graficzne, w moim kompie).</p> <p>Niedługo będzie o pisaniu aplikacji do facebooka. A teraz sobie wymyślam jak powinien wyglądać serwis opiwo.com (czy raczej jak działać), żeby każdego chwycił za serce i spowodował efekt ŁAŁ.</p> <p>Szczegóły wkrótce.</p> <p>PS: Jeszcze chciałem przeprosić, że przynudzałem tak długo o tym JSON-RPC. Jak ktoś chętny: <a href="http://piotr.gabryjeluk.pl/local--files/dev:po-devcampie/od-ramek-do-json-rpc.pdf">oto prezentacja</a>.</p> <p>by <span class="printuser avatarhover"><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank"><img class="small" src="http://www.wikidot.com/avatar.php?userid=2462&amp;size=small&amp;timestamp=1328999363" alt="Gabrys" style="background-image:url(http://www.wikidot.com/userkarma.php?u=2462)" /></a><a href="http://piotr.gabryjeluk.pl/profile2:2462" target="_blank">Gabrys</a></span></p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>
