<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Generating random strings in Erlang</title>
	<atom:link href="http://blog.teemu.im/2009/11/07/generating-random-strings-in-erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.teemu.im/2009/11/07/generating-random-strings-in-erlang/</link>
	<description>i'm teemu and this is my weblog</description>
	<lastBuildDate>Wed, 01 Jun 2011 15:00:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: mike</title>
		<link>http://blog.teemu.im/2009/11/07/generating-random-strings-in-erlang/comment-page-1/#comment-1581</link>
		<dc:creator>mike</dc:creator>
		<pubDate>Wed, 01 Jun 2011 15:00:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.teemu.im/?p=287#comment-1581</guid>
		<description>this is my version of random_string:

random_string(0)         -&gt; [];
random_string(Length) -&gt; [random_char() &#124; random_string(Length-1)].
random_char()            -&gt; random:uniform(95) + 31 .</description>
		<content:encoded><![CDATA[<p>this is my version of random_string:</p>
<p>random_string(0)         -> [];<br />
random_string(Length) -> [random_char() | random_string(Length-1)].<br />
random_char()            -> random:uniform(95) + 31 .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jed Olivos</title>
		<link>http://blog.teemu.im/2009/11/07/generating-random-strings-in-erlang/comment-page-1/#comment-1577</link>
		<dc:creator>Jed Olivos</dc:creator>
		<pubDate>Mon, 11 Apr 2011 16:29:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.teemu.im/?p=287#comment-1577</guid>
		<description>A big thank you for your article.Much thanks again. Great.</description>
		<content:encoded><![CDATA[<p>A big thank you for your article.Much thanks again. Great.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: teemu</title>
		<link>http://blog.teemu.im/2009/11/07/generating-random-strings-in-erlang/comment-page-1/#comment-1476</link>
		<dc:creator>teemu</dc:creator>
		<pubDate>Sun, 10 Jan 2010 16:27:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.teemu.im/?p=287#comment-1476</guid>
		<description>Hi Zed,

Thanks for the optimization tips. Using tuple for the AllowedChars didn&#039;t come to my mind, but it makes sense performance wise. And your recursive function is definitely more elegant. I have some learning to do with the functional programming still. :) Still, I wouldn&#039;t say that your example doesn&#039;t need explanation. ;)</description>
		<content:encoded><![CDATA[<p>Hi Zed,</p>
<p>Thanks for the optimization tips. Using tuple for the AllowedChars didn&#8217;t come to my mind, but it makes sense performance wise. And your recursive function is definitely more elegant. I have some learning to do with the functional programming still. <img src='http://blog.teemu.im/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Still, I wouldn&#8217;t say that your example doesn&#8217;t need explanation. <img src='http://blog.teemu.im/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zed</title>
		<link>http://blog.teemu.im/2009/11/07/generating-random-strings-in-erlang/comment-page-1/#comment-1475</link>
		<dc:creator>Zed</dc:creator>
		<pubDate>Wed, 06 Jan 2010 21:56:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.teemu.im/?p=287#comment-1475</guid>
		<description>Just for some premature optimization hints :)
- you are evaluating the length of AllowedChars in each call of your folded function, which is an o(N) operation.
- you could be using an AllowedChars tuple. Accessing the n-th element of a list is o(N), while o(1) for an tuple.

Also instead of the obscure folding you could just create a recursive function for building the list. For example:

random_str(0, _Chars) -&gt; [];
random_str(Len, Chars) -&gt; [random_char(Chars)&#124;random_str(Len-1, Chars)].
random_char(Chars) -&gt; element(random:uniform(tuple_size(Chars)), Chars).

This would render your statement of &quot;Erlang is not the most readable language&quot; pointless, as the code is so readable, it doesn&#039;t even need an explanation :)</description>
		<content:encoded><![CDATA[<p>Just for some premature optimization hints <img src='http://blog.teemu.im/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
- you are evaluating the length of AllowedChars in each call of your folded function, which is an o(N) operation.<br />
- you could be using an AllowedChars tuple. Accessing the n-th element of a list is o(N), while o(1) for an tuple.</p>
<p>Also instead of the obscure folding you could just create a recursive function for building the list. For example:</p>
<p>random_str(0, _Chars) -&gt; [];<br />
random_str(Len, Chars) -&gt; [random_char(Chars)|random_str(Len-1, Chars)].<br />
random_char(Chars) -&gt; element(random:uniform(tuple_size(Chars)), Chars).</p>
<p>This would render your statement of &#8220;Erlang is not the most readable language&#8221; pointless, as the code is so readable, it doesn&#8217;t even need an explanation <img src='http://blog.teemu.im/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

