Added a handy double split tool to ListUtils, may be useful to you in network splitting @unpairedbracket; takes in a double, divides it into a defined amount of segments, giving the top element the remains
This commit is contained in:
parent
646b22f5b5
commit
a93d51a4a1
1 changed files with 17 additions and 0 deletions
|
@ -169,4 +169,21 @@ public class ListUtils
|
|||
{
|
||||
return (List<V>)Arrays.asList(values);
|
||||
}
|
||||
|
||||
public static double[] splitNum(int size, double num)
|
||||
{
|
||||
double[] split = new double[size];
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
double remain = num%size;
|
||||
double ret = (num-remain)/size;
|
||||
ret += remain;
|
||||
|
||||
split[i] = ret;
|
||||
num -= remain;
|
||||
}
|
||||
|
||||
return split;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue