<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3AApril_7</id>
	<title>SE250:April 7 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3AApril_7"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:April_7&amp;action=history"/>
	<updated>2026-04-28T17:12:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:April_7&amp;diff=1772&amp;oldid=prev</id>
		<title>Mark: 6 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:April_7&amp;diff=1772&amp;oldid=prev"/>
		<updated>2008-11-03T05:08:39Z</updated>

		<summary type="html">&lt;p&gt;6 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Agenda ==&lt;br /&gt;
* OK, so I&amp;#039;ve uploaded my &amp;quot;screencast&amp;quot; to my own file host. We had to choose something which was based on Lab 3 correct? But some of it wasn&amp;#039;t exactly ArrayList content. I&amp;#039;ve put my screencast there anyway - work in progress of course.&lt;br /&gt;
&lt;br /&gt;
== Minutes ==&lt;br /&gt;
&lt;br /&gt;
Minute taker: [[User:ssre005|Shrek]]&lt;br /&gt;
&lt;br /&gt;
.talked about screencasts&lt;br /&gt;
&lt;br /&gt;
.lab #5&lt;br /&gt;
&lt;br /&gt;
hash functions&lt;br /&gt;
 - given several hash functions&lt;br /&gt;
 - evaluate 2 experiments&lt;br /&gt;
&lt;br /&gt;
1- given suite (collection of functions) for testing randomness&lt;br /&gt;
&lt;br /&gt;
in each case - an input source (a set of keys to be hashed. Strings or numbers)&lt;br /&gt;
			- input sources may be typical words or sequential integers&lt;br /&gt;
	     - an output of pseudorandomness ( a number)&lt;br /&gt;
&lt;br /&gt;
pseudorandom is not the same as true random as the number returned will be the same if the same input is again used.&lt;br /&gt;
&lt;br /&gt;
2- Test hash function in practice&lt;br /&gt;
&lt;br /&gt;
input source --&amp;gt; hash function --&amp;gt; look at hash table&lt;br /&gt;
&lt;br /&gt;
array&lt;br /&gt;
(numbers on right represent number of entries in each position)&lt;br /&gt;
0    - 3&lt;br /&gt;
-    - 0&lt;br /&gt;
-    - 2&lt;br /&gt;
-    - 2&lt;br /&gt;
-    - 1&lt;br /&gt;
-    - 4&lt;br /&gt;
size - 1&lt;br /&gt;
&lt;br /&gt;
frequency count to check for occurences of each entry for each position (i.e. the length of the chains in the array).&lt;br /&gt;
&lt;br /&gt;
Second test thus gives us an idea of the practical implications of the different types of hash functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Where does randommness come into it? &lt;br /&gt;
&lt;br /&gt;
	hash function:&lt;br /&gt;
		Take a string, from this give me an integer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	Simpler problem:  Take a character, from this give me an integer&lt;br /&gt;
&lt;br /&gt;
	The obvious thing:&lt;br /&gt;
&lt;br /&gt;
	A	0&lt;br /&gt;
	B	1&lt;br /&gt;
	C	2&lt;br /&gt;
	.&lt;br /&gt;
	.&lt;br /&gt;
	.&lt;br /&gt;
	Z	25&lt;br /&gt;
	sp	26&lt;br /&gt;
&lt;br /&gt;
No reason to have consecutive numbers, no reason for them not to be random (lol, can&amp;#039;t remember what he said)&lt;br /&gt;
&lt;br /&gt;
Therefore, random integer 0 ... MAX_INT&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
each entry could be really random like 0xC5C48EA5L, written in hexadecimal to make it look frightening.&lt;br /&gt;
&lt;br /&gt;
Characters are &amp;quot;fired&amp;quot; into a hash function and the value returned could be anywhere along the entire range of 0 - MAXINT.&lt;br /&gt;
&lt;br /&gt;
	int tbl[256] = ( ... )&lt;br /&gt;
		int hash_char( char c) {return tbl[ c]; }&lt;br /&gt;
&lt;br /&gt;
	int hash_string(char*sp) {&lt;br /&gt;
hash_char(sp[0])&lt;br /&gt;
hash_char(sp[1])&lt;br /&gt;
hash_char(sp[2])&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
this is bad.&lt;br /&gt;
&lt;br /&gt;
this is better:&lt;br /&gt;
&lt;br /&gt;
	int hash_string(char*sp) {&lt;br /&gt;
	combine( combine (hash_char(sp[0]), hash_char(sp[1]))&lt;br /&gt;
	hash_char(sp[2])&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int hash_string(char*sp) {&lt;br /&gt;
		int has = &amp;lt;some predetermined random integer&amp;gt;;&lt;br /&gt;
		for(; sp != 0; sp++);&lt;br /&gt;
		hash = combine (hash_char, *sp);&lt;br /&gt;
	return hash;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
to combine two hash codes:&lt;br /&gt;
&lt;br /&gt;
	need to ensure entropy is maximum of each value&lt;br /&gt;
&lt;br /&gt;
	consider:&lt;br /&gt;
&lt;br /&gt;
int combine(int h1, int h2) {&lt;br /&gt;
	return h1 + h2;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
this doesn&amp;#039;t work as it favours a last digit of 0 if the two numbers have zeros for last digits.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
XOR function is better - allows for any input to be shuffled around and changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int combine(int h1, int h2) {&lt;br /&gt;
	return rotate(h1) ^ h2;&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>