<?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>Creations.cl &#187; generador de rut</title>
	<atom:link href="http://www.creations.cl/tag/generador-de-rut/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.creations.cl</link>
	<description>Programación y algo más...</description>
	<lastBuildDate>Sat, 10 Dec 2011 06:50:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generador de Rut y Validador</title>
		<link>http://www.creations.cl/2009/01/generador-de-rut-y-validador/</link>
		<comments>http://www.creations.cl/2009/01/generador-de-rut-y-validador/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 18:34:46 +0000</pubDate>
		<dc:creator>Ancelot</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[desarrollo]]></category>
		<category><![CDATA[generador de rut]]></category>
		<category><![CDATA[informática]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[rut]]></category>
		<category><![CDATA[verificador de rut]]></category>

		<guid isPermaLink="false">http://www.creations.cl/?p=63</guid>
		<description><![CDATA[Muchos han esatdo buscando  una forma de validar si un RUT es válido o no, pero también hay muchos que necesitan probar sus aplicaciones y están usando sus propios RUTs, pero ¿qué pasa cuando necesitas hacer una prueba masivamente?, acá te traigo la solución...
El primer método te devolverá un char con el texto del dígito [...]]]></description>
			<content:encoded><![CDATA[<p>Muchos han esatdo buscando  una forma de validar si un RUT es válido o no, pero también hay muchos que necesitan probar sus aplicaciones y están usando sus propios RUTs, pero ¿qué pasa cuando necesitas hacer una prueba masivamente?, acá te traigo la solución...</p>
<p><span id="more-63"></span>El primer método te devolverá un char con el texto del dígito verificador al RUT que se recibe por parámetro, pero, ¿por qué devuelve char?, fácil, el dígito verificador puede ser una "K", por lo que se devuelve como código ASCII del carácter correspondiente.</p>
<p>Por ejemplo</p>
<div class="igBar"><span id="ljava-5"><a href="#" onclick="javascript:showPlainTxt('java-5'); return false;">TEXTO PLANO</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-5">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#40;</span>char<span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;color:#800000;">45</span> <span style="color: #808080; font-style: italic;">//- eso corresponde a cero 0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#40;</span>char<span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;color:#800000;">75</span> <span style="color: #808080; font-style: italic;">//- eso corresponde a K </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Acá el método que me devuelve el Dígito Verificador.</p>
<div class="igBar"><span id="ljava-6"><a href="#" onclick="javascript:showPlainTxt('java-6'); return false;">TEXTO PLANO</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-6">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> char obtieneDV<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> rut<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> m = <span style="color: #cc66cc;color:#800000;">0</span>, s = <span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>; rut != <span style="color: #cc66cc;color:#800000;">0</span>; rut /= <span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">s = <span style="color: #66cc66;">&#40;</span>s + rut % <span style="color: #cc66cc;color:#800000;">10</span> * <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">9</span> - m++ % <span style="color: #cc66cc;color:#800000;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> % <span style="color: #cc66cc;color:#800000;">11</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>char<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>s != <span style="color: #cc66cc;color:#800000;">0</span> ? s + <span style="color: #cc66cc;color:#800000;">47</span> : <span style="color: #cc66cc;color:#800000;">75</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>El método es super sencillo, pero necesitamos probarlo. Para esto vamos a hacer un for que me genere números al azar que haremos pasar por RUTs y obtendremos el dígito verificador que corresponda, si bien, muchos de estos RUTs no serán reales, sí serán validos y nos servirtán para testear nuestra aplicación.</p>
<div class="igBar"><span id="ljava-7"><a href="#" onclick="javascript:showPlainTxt('java-7'); return false;">TEXTO PLANO</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-7">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> metodoCualquiera<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> i=<span style="color: #cc66cc;color:#800000;">0</span>; i&amp;lt;<span style="color: #cc66cc;color:#800000;">100</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> rut = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Math</span></a>.<span style="color: #006600;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>*<span style="color: #cc66cc;color:#800000;">30000000</span>+<span style="color: #cc66cc;color:#800000;">10000000</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GWT.<span style="color: #006600;">log</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"RUT :"</span>+<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a>.<span style="color: #006600;">valueOf</span><span style="color: #66cc66;">&#40;</span>rut<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">"-"</span>+obtieneDV<span style="color: #66cc66;">&#40;</span>rut<span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a>.<span style="color: #006600;">valueOf</span><span style="color: #66cc66;">&#40;</span>rut<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">"-"</span>+obtieneDV<span style="color: #66cc66;">&#40;</span>rut<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> char obtieneDV<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> rut<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> m = <span style="color: #cc66cc;color:#800000;">0</span>, s = <span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>; rut != <span style="color: #cc66cc;color:#800000;">0</span>; rut /= <span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">s = <span style="color: #66cc66;">&#40;</span>s + rut % <span style="color: #cc66cc;color:#800000;">10</span> * <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">9</span> - m++ % <span style="color: #cc66cc;color:#800000;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> % <span style="color: #cc66cc;color:#800000;">11</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>char<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>s != <span style="color: #cc66cc;color:#800000;">0</span> ? s + <span style="color: #cc66cc;color:#800000;">47</span> : <span style="color: #cc66cc;color:#800000;">75</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Así tendremos una consola con 100 RUTs totalmente válidos y útiles al momento de hacer testing.</p>
<p>Para los que también necesiten un validador de RUT.</p>
<p>Este método es parecido al anterior, sólo que recibe un parámetro má, el DV, así calcula el DV que corresponde al RUT introducido y lo compara con el DV que nosotros le proporcionamos, nos devolverá un "true" en caso de ser iguales y un "false" en caso de no corresponder.</p>
<div class="igBar"><span id="ljava-8"><a href="#" onclick="javascript:showPlainTxt('java-8'); return false;">TEXTO PLANO</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-8">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">boolean</span> verificarRut<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> rut, char dv<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> m = <span style="color: #cc66cc;color:#800000;">0</span>, s = <span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>; rut != <span style="color: #cc66cc;color:#800000;">0</span>; rut /= <span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">s = <span style="color: #66cc66;">&#40;</span>s + rut % <span style="color: #cc66cc;color:#800000;">10</span> * <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">9</span> - m++ % <span style="color: #cc66cc;color:#800000;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> % <span style="color: #cc66cc;color:#800000;">11</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">return</span> dv == <span style="color: #66cc66;">&#40;</span>char<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>s != <span style="color: #cc66cc;color:#800000;">0</span> ? s + <span style="color: #cc66cc;color:#800000;">47</span> : <span style="color: #cc66cc;color:#800000;">75</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.creations.cl/2009/01/generador-de-rut-y-validador/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

