Moved Random utils into their own class

This commit is contained in:
nathan 2017-03-10 17:02:23 +01:00
parent 36f6000b42
commit ef0cfe2f2e
3 changed files with 7 additions and 6 deletions

View File

@ -21,7 +21,7 @@ package dorkbox.util.collections;
import java.util.Arrays;
import dorkbox.util.MathUtil;
import dorkbox.util.RandomUtil;
/** A resizable, ordered or unordered int array. Avoids the boxing that occurs with ArrayList<Integer>. If unordered, this class
* avoids a memory copy when removing elements (the last element is moved to the removed element's position).
@ -291,7 +291,7 @@ public class IntArray {
public void shuffle () {
for (int i = this.size - 1; i >= 0; i--) {
int ii = MathUtil.randomInt(i);
int ii = RandomUtil.int_(i);
int temp = this.items[i];
this.items[i] = this.items[ii];
this.items[ii] = temp;
@ -311,7 +311,7 @@ public class IntArray {
if (this.size == 0) {
return 0;
}
return this.items[MathUtil.randomInt(0, this.size - 1)];
return this.items[RandomUtil.int_(0, this.size - 1)];
}
public int[] toArray () {

View File

@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import dorkbox.util.MathUtil;
import dorkbox.util.RandomUtil;
/** An unordered map that uses int keys. This implementation is a cuckoo hash map using 3 hashes, random walking, and a small stash
* for problematic keys. Null values are allowed. No allocation is done except when growing the table size. <br>
@ -237,7 +238,7 @@ public class IntMap<V> {
int i = 0, pushIterations = this.pushIterations;
do {
// Replace the key and value for one of the hashes.
switch (MathUtil.randomInt(2)) {
switch (RandomUtil.int_(2)) {
case 0:
evictedKey = key1;
evictedValue = valueTable[index1];

View File

@ -17,7 +17,7 @@ package dorkbox.util.collections;
import com.esotericsoftware.kryo.util.ObjectMap;
import dorkbox.util.MathUtil;
import dorkbox.util.RandomUtil;
/** An unordered map where the values are ints. This implementation is a cuckoo hash map using 3 hashes, random walking, and a
* small stash for problematic keys. Null keys are not allowed. No allocation is done except when growing the table size. <br>
@ -210,7 +210,7 @@ public class ObjectIntMap<K> {
int i = 0, pushIterations = this.pushIterations;
do {
// Replace the key and value for one of the hashes.
switch (MathUtil.randomInt(2)) {
switch (RandomUtil.int_(2)) {
case 0:
evictedKey = key1;
evictedValue = valueTable[index1];