From b76ab3cdac8374572c50579ecf3e818dad39acb9 Mon Sep 17 00:00:00 2001 From: David Hoover Date: Tue, 23 Aug 2011 13:33:11 -0700 Subject: [PATCH 1/4] No longer pick from arrays. Per the wailing and gnashing of teeth in response to 7e51d4c and 7bb7ee2, I'll do the extra legwork to keep my bits in a List despite java handing them to me as an array. --- src/main/java/com/samskivert/util/Randoms.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/com/samskivert/util/Randoms.java b/src/main/java/com/samskivert/util/Randoms.java index 74e5f323..4a6e7998 100644 --- a/src/main/java/com/samskivert/util/Randoms.java +++ b/src/main/java/com/samskivert/util/Randoms.java @@ -176,18 +176,6 @@ public class Randoms return pickPluck(iterable, ifEmpty, false); } - /** - * Pick a random element from the specified array, or return ifEmpty - * if it is empty. - * - * @throws NullPointerException if the array is null. - */ - public T pick (T[] array, T ifEmpty) - { - int size = array.length; - return (size == 0) ? ifEmpty : array[_r.nextInt(size)]; - } - /** * Pick a random key from the specified mapping of weight values, or return * ifEmpty if no mapping has a weight greater than 0. Each From cdbf87f7dd8690c97014f651a8fbe5807348c6cd Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 29 Aug 2011 16:48:34 -0700 Subject: [PATCH 2/4] Added another element to list of MAC addresses to ignore. My machine, at least, reports a bunch of these from ipconfig. --- src/main/java/com/samskivert/net/MACUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/samskivert/net/MACUtil.java b/src/main/java/com/samskivert/net/MACUtil.java index f527277e..dbe3e641 100644 --- a/src/main/java/com/samskivert/net/MACUtil.java +++ b/src/main/java/com/samskivert/net/MACUtil.java @@ -75,6 +75,7 @@ public class MACUtil // 02-03-8A-00-00-11 - Westell Dual (USB/Ethernet) modem // FF-FF-FF-FF-FF-FF - Tunnel adapter Teredo // 02-00-4C-4F-4F-50 - MSFT thinger, loopback of some sort + // 00-00-00-00-00-00(-00-E0) - IP6 tunnel if (mac.startsWith("44-45-53")) { continue; } else if (mac.startsWith("00-53-45-00")) { @@ -91,6 +92,8 @@ public class MACUtil continue; } else if (mac.startsWith("02-00-4C-4F-4F-50")) { continue; + } else if (mac.startsWith("00-00-00-00-00-00")) { + continue; } list.add(mac); From 316dea118d8f8eae60dfb84038f17317f950d90d Mon Sep 17 00:00:00 2001 From: David Hoover Date: Fri, 2 Sep 2011 13:10:52 -0700 Subject: [PATCH 3/4] Change Randoms.getProbability to use doubles. Existing callers will merrily promote up, and this way we can match the results over in the actionscript port in aspirin. --- src/main/java/com/samskivert/util/Randoms.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/samskivert/util/Randoms.java b/src/main/java/com/samskivert/util/Randoms.java index 4a6e7998..6694cc21 100644 --- a/src/main/java/com/samskivert/util/Randoms.java +++ b/src/main/java/com/samskivert/util/Randoms.java @@ -106,9 +106,9 @@ public class Randoms /** * Has a probability p of returning true. */ - public boolean getProbability (float p) + public boolean getProbability (double p) { - return _r.nextFloat() < p; + return _r.nextDouble() < p; } /** From ab23b714e08d42b9fb6d40ae104d249a4ca531bf Mon Sep 17 00:00:00 2001 From: David Hoover Date: Fri, 2 Sep 2011 13:13:18 -0700 Subject: [PATCH 4/4] Some Randoms methods for doubles. --- .../java/com/samskivert/util/Randoms.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/samskivert/util/Randoms.java b/src/main/java/com/samskivert/util/Randoms.java index 6694cc21..630c25bb 100644 --- a/src/main/java/com/samskivert/util/Randoms.java +++ b/src/main/java/com/samskivert/util/Randoms.java @@ -93,6 +93,26 @@ public class Randoms return low + (_r.nextFloat() * (high - low)); } + /** + * Returns a pseudorandom, uniformly distributed double value between + * 0.0 (inclusive) and the high (exclusive). + * + * @param high the high value limiting the random number sought. + */ + public double getDouble (double high) + { + return _r.nextDouble() * high; + } + + /** + * Returns a pseudorandom, uniformly distributed double value between + * low (inclusive) and high (exclusive). + */ + public double getInRange (double low, double high) + { + return low + (_r.nextDouble() * (high - low)); + } + /** * Returns true approximately one in n times. *