@Override public int hashCode() { int result = rand != null ? rand.hashCode() : 0; result = 31 * result + hitpoints; result = 31 * result + goldpieces; result = 31 * result + (allAttributes != null ? allAttributes.hashCode() : 0); result = 31 * rand.nextInt(); return result; }
private int[] getNewList(int size, int min, int max) { int[] returnArray = new int[size]; try { URL randomOrg = new URL( "http://www.random.org/cgi-bin/randnum?" + "num=" + size + "&min=" + min + "&max=" + max + "&col=1"); HttpURLConnection con = (HttpURLConnection) randomOrg.openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); InputStream in = con.getInputStream(); InputStreamReader isr = new InputStreamReader(in); BufferedReader br = new BufferedReader(isr); String theLine; for (int i = 0; i < size; i++) { returnArray[i] = Integer.parseInt(br.readLine()); } con.disconnect(); } // if something fails, revert to something a little less random, but still good // the hashCode is based on the objects memory address, which is unique for each object catch (Exception e) { Random r = new Random(); r.setSeed(r.hashCode()); for (int i = 0; i < size; i++) returnArray[i] = r.nextInt(max); } return returnArray; }