darkmasta
08.05.2008, 13:35
Hallo!
In der letzten technische Informatikvorlesung behandelten wir Hash-tables.
Als hashfunktion die modulo. der Professor meinte, dass als Divisor eine Primzahl verwendet werden soll, da damit weniger kollisionen auftreten.
Das kann ich mir nicht vorstellen, daher wollte ich das mit einem Programm überprüfen. damit entstand aber nicht das zu erwatete ergebniss: verteilung war bei primzahl/nichtprimzahl gleich
import java.util.Random;
import java.util.*;
/*
* verteilung.java
*
* Created on 8. Mai 2008, 13:17
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author kj
*/
public class verteilung {
/** Creates a new instance of verteilung */
public verteilung() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application lo
int i,f;
int[] a= new int [50];
int z=50;
int[] b= new int [53];
int x=53;
// 0 - 49999
for (i=0;i<1000*z;i++){
f=(int) ( (int)(Math.random()*1000*z) % z);
a[f]+=1;
}
Arrays.sort(a,0,50);
for (i=0;i<1000*x;i++){
f=(int) ( (int)(Math.random()*1000*x) % x);
b[f]+=1;
}
Arrays.sort(b,0,53);
for(i=0; i < 50;i++){
System.out.println(a[i]+ " " +b[i]);
}
System.out.println(" "+b[50]);
System.out.println(" "+b[51]);
System.out.println(" "+b[52]);
}
}
ist das Programm falsch?
kennt jemand einen mathematischen Hintergrund??
Hab meinen Infoprofessor darauf angesprochen, dieser hat das auch noch nie überprüft und weiß auch keine Antwort! o_o
mfg
J.K.
In der letzten technische Informatikvorlesung behandelten wir Hash-tables.
Als hashfunktion die modulo. der Professor meinte, dass als Divisor eine Primzahl verwendet werden soll, da damit weniger kollisionen auftreten.
Das kann ich mir nicht vorstellen, daher wollte ich das mit einem Programm überprüfen. damit entstand aber nicht das zu erwatete ergebniss: verteilung war bei primzahl/nichtprimzahl gleich
import java.util.Random;
import java.util.*;
/*
* verteilung.java
*
* Created on 8. Mai 2008, 13:17
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author kj
*/
public class verteilung {
/** Creates a new instance of verteilung */
public verteilung() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application lo
int i,f;
int[] a= new int [50];
int z=50;
int[] b= new int [53];
int x=53;
// 0 - 49999
for (i=0;i<1000*z;i++){
f=(int) ( (int)(Math.random()*1000*z) % z);
a[f]+=1;
}
Arrays.sort(a,0,50);
for (i=0;i<1000*x;i++){
f=(int) ( (int)(Math.random()*1000*x) % x);
b[f]+=1;
}
Arrays.sort(b,0,53);
for(i=0; i < 50;i++){
System.out.println(a[i]+ " " +b[i]);
}
System.out.println(" "+b[50]);
System.out.println(" "+b[51]);
System.out.println(" "+b[52]);
}
}
ist das Programm falsch?
kennt jemand einen mathematischen Hintergrund??
Hab meinen Infoprofessor darauf angesprochen, dieser hat das auch noch nie überprüft und weiß auch keine Antwort! o_o
mfg
J.K.