<?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>Name Generators Blog &#187; tutorial</title>
	<atom:link href="http://www.name-generators.com/tag/tutorial/feed" rel="self" type="application/rss+xml" />
	<link>http://www.name-generators.com</link>
	<description>Blogging about name generators</description>
	<lastBuildDate>Sun, 04 Dec 2011 17:28:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to make binary to decimal conversion in JavaScript</title>
		<link>http://www.name-generators.com/javascript-2/how-to-make-binary-decimal-conversion-in-javascript.htm</link>
		<comments>http://www.name-generators.com/javascript-2/how-to-make-binary-decimal-conversion-in-javascript.htm#comments</comments>
		<pubDate>Sun, 31 Oct 2010 10:40:52 +0000</pubDate>
		<dc:creator>Niels</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[converter]]></category>
		<category><![CDATA[decimal]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.name-generators.com/?p=382</guid>
		<description><![CDATA[Conversion between binary and decimal is very easy in JavaScript.  This tutorial will show you how to make a binary to decimal converter and vice versa. But conversion from binary to hexadecimal is just as simple. JavaScript has some nice &#8230; <a href="http://www.name-generators.com/javascript-2/how-to-make-binary-decimal-conversion-in-javascript.htm">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Conversion between binary and decimal is very easy in JavaScript.  This tutorial will show you how to make a binary to decimal converter and vice versa. But conversion from binary to hexadecimal is just as simple. JavaScript has some nice build in function that making it extremely easy to convert from one numeral system to another.</p>
<h3>Binary to decimal converter script</h3>
<p>Let first take a look at how you make a binary to decimal converter script:</p>
<pre lang="javascript">function convertBinary(){
   var binaryNumber = document.getElementById('binary').value;
   binaryNumber = parseInt(binaryNumber,2);
   var decimalNumber = binaryNumber.toString(10);
   alert(decimalNumber)
 }
</pre>
<p>First you need to get the input form the user. I assume you have made a input text filed with the ID=&#8221;binary&#8221; in your HTML.</p>
<p>Then you have to parse that input to an integer. This operation is very basic JavaScript but be aware the second parameter (radix) in the parseInt function. The radix is optional. A number (from 2 to 36) that represents the numeral system to be used. Using 2 as the radix tells JavaScript to parse it into the binary numeral system.</p>
<p>Finally we use JavaScript toString function to convert the number into a string. The parameter 10(again called radix in this function) tells Javascript, that we want to use the decimal numeral system in this conversion.</p>
<p>Now we just need to alert the converted number, and we are done. Very simple and very easy.</p>
<h3>Decimal to binary converter script</h3>
<p>And here&#8217;s how to make a decimal to binary converter script. This conversion is just as simple.</p>
<pre lang="javascript"> function convertDecimal(){
   var decimalNumber = document.getElementById('decimal').value;
   decimalNumber = parseInt(decimalNumber);
   var binaryNumber = decimalNumber.toString(2);
   alert(binaryNumber)
 }</pre>
<p>This decimal to binary converter script is basically the same as in the above. The only change is that we don&#8217;t need the second radix parameter to the parseInt function. JavaScript assume per default that we want to parse to integer using the decimal number system.</p>
<h3>How to make a Hexadecimal converter</h3>
<p>Just as simple as the 2 above examples. You just need to use the right radix in the 2 JavaScript functions as already explained. the radix in the Hexadecimal numeral system is 16.</p>
<h3>Finalization of the converter scripts</h3>
<p>Now you just need to put the JavaScript and HTML together. This can be done in a lot of ways. I have made an example of a <a title="Binary to decimal converter" href="http://www.name-generators.com/generators/binary-decimal-converter.html" target="_blank">Binary to Decimal converter</a>. Just right click and choose &#8220;view source&#8221; to view the code. You are of course welcome to copy the Binary to Decimal converter code and use as a base for your own experiments.</p>
<h3>Binary &#8211; Decimal resources</h3>
<p><a title="Binary numeral system at the Wiki" href="http://en.wikipedia.org/wiki/Binary_numeral_system" target="_blank">Binary numeral system</a>, <a title="Decimal numeral system at the Wiki" href="http://en.wikipedia.org/wiki/Decimal" target="_blank">Decimal numeral system</a> and <a title="Hexadecimal numeral system at the Wiki" href="http://en.wikipedia.org/wiki/Hexadecimal" target="_blank">Hexadecimal numeral system</a>. Great descriptions description of the Binary, Decimal and Hexadecimal numeral system at Wikipedia. Lots of facts about history,  representation, counting and calculating using the numeral systems.</p>
<p><a title="ParseInt at w3schools" href="http://www.w3schools.com/jsref/jsref_parseint.asp" target="_blank">parseInt at W3 schools</a>. W3 schools is a great place to learn basic JavaScript.</p>
<p><a title="Binary to decimal converter" href="../generators/binary-decimal-converter.html" target="_blank">Binary to Decimal converter</a>. An example script that makes both Binary to Decimal and Decimal to Binary conversions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.name-generators.com/javascript-2/how-to-make-binary-decimal-conversion-in-javascript.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Random name generator in Python</title>
		<link>http://www.name-generators.com/name-generators/random-name-generator-in-python.htm</link>
		<comments>http://www.name-generators.com/name-generators/random-name-generator-in-python.htm#comments</comments>
		<pubDate>Sat, 04 Sep 2010 19:25:52 +0000</pubDate>
		<dc:creator>Niels</dc:creator>
				<category><![CDATA[Name generator stuff]]></category>
		<category><![CDATA[name generator]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.name-generators.com/?p=254</guid>
		<description><![CDATA[In this short tutorial I will show you how to make a random name generator in Python. If you came here looking for some cool random names visit the online name generators. The name generator script Open IDLE which is &#8230; <a href="http://www.name-generators.com/name-generators/random-name-generator-in-python.htm">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this short tutorial I will show you how to make a random name generator in Python.</p>
<p>If you came here looking for some cool random names visit the online<strong> <a title="Name generators" href="http://online-generator.com/" target="_blank">name generators</a></strong>.</p>
<h3>The name generator script</h3>
<p>Open IDLE which is the Python supplied IDE or editor (Go to the bottom of the post to see, how you get started with Python).</p>
<p>Open a new window from the file menu and write the following name generator script into this window.</p>
<pre lang="python" line="1">def name_generator():
  import random
  color = ["Red","Blue","Black","White"]
  tool = ["Hammer","Drill","Cutter","Knife"]
  randomNumber1 = random.randrange(0,len(color))
  randomNumber2 = random.randrange(0,len(tool))
  name = color[randomNumber1] + " " + tool[randomNumber2]
  print(name)

name_generator()

(Be aware that copy-paste from the blog may give syntax errors!
 A correct indent is an important element Python syntax!)
</pre>
<p>Save it as name-generator.py.  Now you can run the python program by pressing F5.</p>
<h3>Name generator walk through</h3>
<p>Lets walk through the python script, line by line.</p>
<ol>
<li>In the first line we define our name generator function.</li>
<li>Then we import the random module, so we can call the random function later on.</li>
<li>In line define 2 arrays (color and tool) and asign values to them</li>
<li>Then we make 2 random numbers based on the length of our arrays. The randrage() function returns an integer in the range defined by the parameters. As parameters we use 0 and the len() function to count the numbers of words in the arrays.</li>
<li>In line 7 and 8 we make the final name and print it on the screen.</li>
<li>Finally we call the name generator function, we have just written.</li>
</ol>
<p>That&#8217;s all it takes to make a simple Python random name generator. When you this basic functionality it&#8217;s easy to experiment and develop the random name generator to suit your needs and wishes.</p>
<h3>Name generator inspiration</h3>
<p>For inspiration visit the <a title="Name generators" href="http://online-generator.com/" target="_blank">name generators</a> where you can find a lot of name generators in several genres. From random names over fantasy and nicknames to band and business names.</p>
<h3>Python Beginner guides and tutorials</h3>
<p>Python is a free scripting language running on all platforms from  Linux to Windows. Python is a relative easy programming language and a  name generator is a simple application so it&#8217;s a good place to start if  you wanna learn some programming.</p>
<p>If you haven&#8217;t Python installed at your computer you can download it at <a title="Download Python" href="http://www.python.org/download/" target="_blank">Python.org</a>. This name generator script is based on python 3.12, which is the newest stable version at the moment.</p>
<p>At python.org you can find an excellent <a title="Python tutorial" href="http://docs.python.org/py3k/tutorial/index.html" target="_blank">Python tutorial</a>. And you can find much more about how to use the <a title="Random module in Python" href="http://docs.python.org/py3k/library/random.html">Random function in Python</a>.</p>
<p>Or visit this <a title="Python beginner guide" href="http://wiki.python.org/moin/BeginnersGuide" target="_blank">beginner guide to Python</a> which contains lots of links and resources.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.name-generators.com/name-generators/random-name-generator-in-python.htm/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to make a name generator</title>
		<link>http://www.name-generators.com/name-generators/how-to-make-name-generator.htm</link>
		<comments>http://www.name-generators.com/name-generators/how-to-make-name-generator.htm#comments</comments>
		<pubDate>Sat, 08 May 2010 18:26:05 +0000</pubDate>
		<dc:creator>Niels</dc:creator>
				<category><![CDATA[Name generator stuff]]></category>
		<category><![CDATA[name generator]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.name-generators.com/?p=143</guid>
		<description><![CDATA[In this tutorial I&#8217;ll show how to make a simple name generator. A sort of  &#8220;build your own name generator&#8221; to experiment with. You just need to add your own word lists and you&#8217;re up and running.  But you can &#8230; <a href="http://www.name-generators.com/name-generators/how-to-make-name-generator.htm">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;ll show how to make a simple name generator. A sort of  &#8220;build your own name generator&#8221; to experiment with. You just need to add your own word lists and you&#8217;re up and running.  But you can expand and modify the  name generator code to your own likings   and abilities.</p>
<p>The name generator tutorial is very simple and are aimed at absolute beginners in web programming.</p>
<p>But enough talk, here is some name generator code that makes superhero names:</p>
<pre lang="javascript">function generator(){
  // Add your own words to the wordlist. Be carefull to obey the showed syntax
  var adjectives = ["Cool","Masked","Bloody","Lame"]
  var animals = ["Hamster","Moose","Lama","Duck"]

  // Random numbers are made
  var randomNumber1 = parseInt(Math.random() * adjectives.length);
  var randomNumber2 = parseInt(Math.random() * animals.length);
  var name = adjectives[randomNumber1] + " " + animals[randomNumber2];

  alert(name); //Delete this when the below works            

  //If there's already a name it is removed  
  if(document.getElementById("result")){
    document.getElementById("placeholder").removeChild(document.getElementById("result"));
  }
  // A div element is created to show the generated name.
  //The Name is added as a textnode. Textnode is added to the placeholder.
  var element = document.createElement("div");
  element.setAttribute("id", "result");
  element.appendChild(document.createTextNode(name));
  document.getElementById("placeholder").appendChild(element);
}</pre>
<p>The script is a simplified version of the one I use to make <a title="Superhero names" href="http://online-generator.com/name-generator/superhero-name-generator.php" target="_blank">superhero names</a> with my superhero generator.</p>
<h3 style="font-size: 20px; margin-bottom: 10px;">The name generator piece by piece</h3>
<h3>The arrays</h3>
<p>The most important part of  the name generator is the word lists. The more words in the list the more variety in the output. So the first part to do is to create a couple of arrays holding all our cool words:</p>
<pre lang="javascript">var adjectives = ["cool","masked","bloody","lame"];
var animals = ["hamster","moose","lama","duck"]</pre>
<p>To retrieve data  from the list we call the name of array with the count of the word as a parameter in a square bracket.  Be aware that counting in programming almost always starts at zero and not at 1.</p>
<p>So adjectives[0] is cool and  animals[1] gives moose</p>
<h3>Randomness</h3>
<p>We of course want random names, so we need to replace the hard coded numbers with random numbers. In our case numbers between 0 and 3 because we have 4 words in our lists. Instead of counting the words ourself, we do that we let the JavaScript length function do the counting. Then we multiply it with a random floating-point number between 0 and 0.9999999999999. Finally we use the parseInt funktion to make the floating-point number into a integer.</p>
<p>All sounds a bit complicated but code wise  it&#8217;s  quite easy.</p>
<pre lang="javascript">randomNumber1 = parseInt(Math.random() * adjectives.length);
randomNumber2 = parseInt(Math.random() * animals.length);</pre>
<h3>The output</h3>
<p>The most simple way to output the name is using the alert function. I use it only to check the generated name cause,  the alert box is  very annoying. So just delete the line, when the code below is up an running.</p>
<p>We will use 7 extra lines to integrate the result into the web page in a more natural way.</p>
<p>But before we begin you need to make an empty div tag in your HTML:</p>
<p>&lt;div id=&#8221;placeholder&#8221;&gt;&lt;/div&gt;</p>
<p>And here are the 7 lines that write the result in the page..</p>
<pre lang="javascript">if(document.getElementById("result")){
  document.getElementById("placeholder").removeChild(document.getElementById("result"));
}

element = document.createElement("div");
element.setAttribute("id", "result");
element.appendChild(document.createTextNode(name));
document.getElementById("placeholder").appendChild(element);</pre>
<p>In short it works like this:</p>
<ol>
<li>If there&#8217;s already a result it is removed</li>
<li>Then a new div element to hold the result  is created</li>
<li>The name is added as a text node</li>
<li>Finally the element is appended to a placeholder in the HTML.</li>
</ol>
<p>When this part works, you can delete the alert(name) from the script.</p>
<h3>Putting it all together</h3>
<p>The generator function can either be included in the head of the HTML document or you can place it in a external JavaScript file.</p>
<p>Now you can call the function from your HTML page.  I always do it 2 places. First in the body tag with an onload event. The generator function then also runs when the page is loaded.</p>
<p>&lt;body onload=&#8221;generator()&#8221;&gt;</p>
<p>And then I also call the JavaScript function on a button:</p>
<p>&lt;input type=&#8221;button&#8221; onclick=&#8221;generator()&#8221; /&gt;</p>
<h3>Download the name generator script</h3>
<p><a title="Download name generator script as zip file" href="http://www.name-generators.com/name-generators/download/name-generator-script.zip">Download name generator script here</a> and read the description of <a title="Name generator script" href="http://www.name-generators.com/name-generators/name-generator-script.htm">how to make the name generator script work</a>.</p>
<h3>Extra funcionality</h3>
<p>The random functions in this guide is very simple. At some time you&#8217;ll probably want to make more complex and interesting names. Here you can see <a title="Make more complex random names" href="http://www.name-generators.com/name-generators/complex-random-names.htm">how to make more complex random names</a>.</p>
<p>On all of my name generators I also have a save list, which saves all the generated names to a list. Read here <a title="Add a save list to name generator" href="http://www.name-generators.com/name-generators/save-name-generator-names.htm">how to add a save list to the name generator</a>.</p>
<h3>Want a review of your name generator?</h3>
<p>Write a comment if  you make a cool name generator with this script. I might very well  write a review of it.  <img src='http://www.name-generators.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also remember to visit my name generators to see  how I make <a title="Superhero name" href="http://online-generator.com/name-generator/superhero-name-generator.php" target="_blank">superhero names</a> with the superhero generator.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.name-generators.com/name-generators/how-to-make-name-generator.htm/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

