<?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>Comentários sobre: Gerando uma String Randomicamente com Ruby on Rails</title>
	<atom:link href="http://www.dica1.com.br/gerando-uma-string-randomicamente-com-ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dica1.com.br/gerando-uma-string-randomicamente-com-ruby-on-rails/</link>
	<description>A melhor dica da internet.</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:31:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Por: jRoque</title>
		<link>http://www.dica1.com.br/gerando-uma-string-randomicamente-com-ruby-on-rails/comment-page-1/#comment-946</link>
		<dc:creator>jRoque</dc:creator>
		<pubDate>Sun, 26 Jul 2009 15:24:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.dica1.com.br/?p=147#comment-946</guid>
		<description>Aceitando o desafio do colega Luan, minha contribuição em JavaScript :D

//Extendendo a classe String, nativa do JS para adcionar o metodo getRandonString.

&lt;code lang=&quot;javascript&quot;&gt;
String.prototype.getRandonString = function(){
        n = 4;
        var result = &quot;&quot;;
        var possible = &quot;abcdefghijlmnopqrstuvxz0123456789&quot;;
        for(i=1;i&lt;=n;i++){
                var rand_no;
                do{
                        rand_no = Math.ceil(Math.random() * 100)-1;
                }while(rand_no&gt;possible.length-1)
                result += possible.charAt(rand_no);
        }
        delete(i);
        return result;
}
var meuTexto = String().getRandonString();
&lt;/code&gt;

</description>
		<content:encoded><![CDATA[<p>Aceitando o desafio do colega Luan, minha contribuição em JavaScript <img src='http://www.dica1.com.br/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>//Extendendo a classe String, nativa do JS para adcionar o metodo getRandonString.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getRandonString</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; n <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> possible <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;abcdefghijlmnopqrstuvxz0123456789&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>n<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> rand_no<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">do</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rand_no <span style="color: #339933;">=</span> Math.<span style="color: #660066;">ceil</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>rand_no<span style="color: #339933;">&gt;</span>possible.<span style="color: #660066;">length</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">+=</span> possible.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>rand_no<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">delete</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> result<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> meuTexto <span style="color: #339933;">=</span> String<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getRandonString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
	</item>
</channel>
</rss>

