<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simon Cook &#187; /dev/random</title>
	<atom:link href="http://simoncook.org/blog/tag/devrandom/feed/" rel="self" type="application/rss+xml" />
	<link>http://simoncook.org</link>
	<description>The future is... on a CD? Now where&#039;s that blasted disc gone?</description>
	<lastBuildDate>Sun, 22 Aug 2010 19:43:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Pulling random data from /dev/random</title>
		<link>http://simoncook.org/blog/2010/02/pulling-random-data-from-devrandom/</link>
		<comments>http://simoncook.org/blog/2010/02/pulling-random-data-from-devrandom/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 06:55:44 +0000</pubDate>
		<dc:creator>Si</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[/dev/random]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://simoncook.org/?p=408</guid>
		<description><![CDATA[This is a shell script that will pull 5 random characters from /dev/random and print them out to standard output. It was created as the input component for a random password generator that I am currently writing. Note on using /dev/random: as usual, using this source for entropy will give you pure randomness, though due [...]]]></description>
			<content:encoded><![CDATA[<p>This is a shell script that will pull 5 random characters from /dev/random and print them out to standard output. It was created as the input component for a random password generator that I am currently writing.</p>
<p><strong>Note on using /dev/random</strong>: as usual, using this source for entropy will give you pure randomness, though due to the nature of the random source (see <a href="http://en.wikipedia.org/wiki//dev/random">Wikipedia entry on /dev/random</a>) the script may sometimes lock up and fail to generate a complete output, as it has run out of randomness. If you are intending to use this alot, then it is advised to use /dev/urandom that doesn&#8217;t block, although that comes at the cost of a small bit of entropy.<br />
<span id="more-408"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Script for pulling x characters from a random source</span>
<span style="color: #666666; font-style: italic;">#   and prints them out to stdout</span>
<span style="color: #666666; font-style: italic;"># Version 1.0.0</span>
<span style="color: #666666; font-style: italic;"># By Simon Cook (http://simoncook.org)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Fill in the two variables below</span>
<span style="color: #666666; font-style: italic;">#  &quot;entropy&quot; is the source of randomness</span>
<span style="color: #666666; font-style: italic;">#  &quot;chars&quot; is the number of chars we want</span>
<span style="color: #007800;">entropy</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>random
<span style="color: #007800;">chars</span>=<span style="color: #000000;">5</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Pull x characters from source</span>
<span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-n1</span> char
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$char</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> i++ <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$chars</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #ff0000;">&quot;<span style="color: #007800;">$entropy</span>&quot;</span></pre></div></div>

<p><strong> Licensing:</strong> This small script is released under the CC-GNU GPL licence.</p>
<p><!-- Creative Commons License --><br />
<a href="http://creativecommons.org/licenses/GPL/2.0/"><br />
<img src="http://creativecommons.org/images/public/cc-GPL-a.png" border="0" alt="CC-GNU GPL" /></a><!-- /Creative Commons License -->.</p>
]]></content:encoded>
			<wfw:commentRss>http://simoncook.org/blog/2010/02/pulling-random-data-from-devrandom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
