<?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>Paul Legato &#187; randomness</title>
	<atom:link href="http://www.paullegato.com/blog/tag/randomness/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paullegato.com</link>
	<description></description>
	<lastBuildDate>Tue, 06 Dec 2011 00:52:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Randomness with Clojure</title>
		<link>http://www.paullegato.com/blog/randomness-clojure/</link>
		<comments>http://www.paullegato.com/blog/randomness-clojure/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 05:58:49 +0000</pubDate>
		<dc:creator>Paul Legato</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[randomness]]></category>

		<guid isPermaLink="false">http://www.paullegato.com/?p=234</guid>
		<description><![CDATA[Psyleron sells a hardware random number generator and software for experimentation on the interaction of consciousness and randomness. As the Psyleron system only runs on Windows, I wrote some quick Clojure to do experimentation with randomness.]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.psyleron.com/" >Psyleron</a> sells a hardware random number generator and associated software package for experimentation on the interaction of consciousness and randomness. No, don&#8217;t laugh. <a target="_blank" href="http://www.princeton.edu/~pear/" >Princeton Engineering Anomalies Research</a> conducted decades of methodologically rigorous <a target="_blank" href="http://www.princeton.edu/~pear/human_machine.html"  class="broken_link">research into the nature of randomness</a>. They concluded that deliberate conscious intention can produce a small but statistically significant and reproducible effect on the outcome of stochastic processes. Psyleron is a commercial offshoot of PEAR.</p>
<p>The Psyleron system, unfortunately, costs hundreds of dollars and only runs on Windows, so I wrote some quick Clojure to do experimentation with randomness, using <a target="_blank" href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man4/random.4.html" >/dev/random</a> as the source. (It appears that <a target="_blank" href="http://www.mail-archive.com/cryptography@metzdowd.com/msg00620.html" >/dev/random on Mac OS X does not provide the same quality guarantees</a> as it does on Linux, but it&#8217;s fine for a prototype and the implementation allows easy substitution of another randomness source later.)<span id="more-234"></span></p>
<h2>Clojure random walk generator</h2>
<pre class="brush: clojure; title: ; notranslate">
(ns randomwalker.core
  (:use [incanter core charts]))

(defn random-walk
  &quot;Returns a random walk of length steps. random-fn should return a random integer.&quot;
  [steps list random-fn]
  (if (= 1 steps)
    list
    (recur (dec steps)
           (conj list
                   (+
                    (if (odd? (random-fn)) 1 -1)
                    (or (last list) 0)))
           random-fn)))

(defn dev-random-walk
  &quot;Returns a random walk of length steps based on random numbers read from /dev/random.&quot;
  [steps]
  (with-open [random (java.io.FileInputStream. &quot;/dev/random&quot;)]
    (random-walk steps [0] (fn [] (.read random)))))

(defn view-walk
  &quot;Visualize a random walk.&quot;
  [steps]
  (view (incanter.charts/xy-plot (range 0 (dec steps)) (dev-random-walk steps))))

(defn walk-ratio
  &quot;Generates the given number of random walks and returns the ratio of (walks ending &gt; 0) / (walks ending &lt; 0).&quot;
  [runs steps-per-run greater less]
  (if (zero? runs)
    (double (/ greater less))
    (let [final (last (dev-random-walk steps-per-run))
          ;foo (println final)
          new-greater (if (&gt; final 0) (inc greater) greater)
          new-less (if (&lt; final 0) (inc less) less)]
      (recur (dec runs) steps-per-run new-greater new-less))))
</pre>
<p>This code generates a simple <a target="_blank" href="http://en.wikipedia.org/wiki/Random_walk" >random walk</a>. The user can easily visualize the random walk with <a target="_blank" href="http://incanter.org/" >Incanter</a>, and it looks suspiciously like <a target="_blank" href="http://www.google.com/finance?q=INDEXSP:.INX" >a stock chart</a>.<div id="attachment_236"  class="wp-caption alignright"  style="width: 310px;"><a href="http://www.paullegato.com/wp-content/uploads/2010/04/Clojure-Random-Walker.png"  class="galleryAndCaptionItem" title="Screenshot of the Clojure Random Walker in action"><img src="http://www.paullegato.com/wp-content/uploads/2010/04/Clojure-Random-Walker-300x248.png" alt="Clojure Random Walker screenshot" title="Clojure Random Walker" width="300" height="248" class="size-medium wp-image-236"/></a><span class="wp-caption-text">Screenshot of the Clojure Random Walker in action</span></div></p>
<p>Psyleron type functionality first vaguely appears in <code>walk-ratio</code>. This generates the requested number of random walks and returns the ratio of those that ended above zero to those that ended below. I imagine this will become the basis for some <a target="_blank" href="http://www.psyleron.com/software_reflector.aspx" >Psyleron Reflector</a> style games and experiments.</p>
<p>This is probably not the most efficient way to implement this; any suggestions are welcome. Any ideas for a better source of randomness? Any insight into how the Psyleron games work? Their descriptions are a bit short on the details.</p>
<img src="http://www.paullegato.com/?ak_action=api_record_view&id=234&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.paullegato.com/blog/randomness-clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

