v3.1.0: added a new type of standard room to replace empty ones
This commit is contained in:
@@ -171,19 +171,24 @@ public class Random {
|
||||
}
|
||||
|
||||
//returns an index from chances, the probability of each index is the weight values in changes
|
||||
//negative values are treated as 0
|
||||
public static int chances( float[] chances ) {
|
||||
|
||||
int length = chances.length;
|
||||
|
||||
float sum = 0;
|
||||
for (int i=0; i < length; i++) {
|
||||
sum += chances[i];
|
||||
sum += Math.max(0, chances[i]);
|
||||
}
|
||||
|
||||
if (sum <= 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
float value = Float( sum );
|
||||
sum = 0;
|
||||
for (int i=0; i < length; i++) {
|
||||
sum += chances[i];
|
||||
sum += Math.max(0, chances[i]);
|
||||
if (value < sum) {
|
||||
return i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user