Gohulan
2005-01-20 06:58:21 UTC
Here is a piece of code that prints out to a text file hashcodes of
randomly generated rational numbers. You can use excel to import the
file and then analyze the results. Currently it generates 1000 random
rational numbers but you can change the amount by changing the loop
variable.
---------------------------------------------------------------------
import java.util.Random;
import java.io.*;
public void setNumerator(int n) {
this.numerator = n;
}
public void setDenominator(int d) {
this.denominator = d;
}
public static void main(String[] args) throws IOException {
File fileName = new File("C:\\hashcodes.txt");
FileWriter out = new FileWriter(fileName);
Rational r = new Rational(0, 1);
Random rn = new Random();
Random rn2 = new Random();
for (int i = 0; i <= 1000; i++) {
r.setNumerator(rn.nextInt());
r.setDenominator(rn.nextInt());
out.write(r + "," + r.hashCode() + "\n");
System.out.println(r + "," + r.hashCode());
}
out.close();
}
------------------------------------------------------------------------
Cheers,
Gohulan.
randomly generated rational numbers. You can use excel to import the
file and then analyze the results. Currently it generates 1000 random
rational numbers but you can change the amount by changing the loop
variable.
---------------------------------------------------------------------
import java.util.Random;
import java.io.*;
public void setNumerator(int n) {
this.numerator = n;
}
public void setDenominator(int d) {
this.denominator = d;
}
public static void main(String[] args) throws IOException {
File fileName = new File("C:\\hashcodes.txt");
FileWriter out = new FileWriter(fileName);
Rational r = new Rational(0, 1);
Random rn = new Random();
Random rn2 = new Random();
for (int i = 0; i <= 1000; i++) {
r.setNumerator(rn.nextInt());
r.setDenominator(rn.nextInt());
out.write(r + "," + r.hashCode() + "\n");
System.out.println(r + "," + r.hashCode());
}
out.close();
}
------------------------------------------------------------------------
Cheers,
Gohulan.