public static int dice(int num, int faces) { int result = 0; // Roll however many dice as necessary for (int i = 0; i < num; i++) { result += Compute.randomInt(faces) + 1; } return result; }
public static int getRandomMechWeight() { int roll = Compute.randomInt(10); if (roll <= 2) return EntityWeightClass.WEIGHT_LIGHT; if (roll <= 6) return EntityWeightClass.WEIGHT_MEDIUM; if (roll <= 8) return EntityWeightClass.WEIGHT_HEAVY; return EntityWeightClass.WEIGHT_ASSAULT; }
public static int getRandomAeroWeight() { int roll = Compute.randomInt(8); if (roll <= 2) return EntityWeightClass.WEIGHT_LIGHT; if (roll <= 6) return EntityWeightClass.WEIGHT_MEDIUM; return EntityWeightClass.WEIGHT_HEAVY; }
public void setLightConditions() { light = PlanetaryConditions.L_DAY; int roll = Compute.randomInt(10) + 1; if (roll < 6) light = PlanetaryConditions.L_DAY; else if (roll < 8) light = PlanetaryConditions.L_DUSK; else if (roll == 8) light = PlanetaryConditions.L_FULL_MOON; else if (roll == 9) light = PlanetaryConditions.L_MOONLESS; else light = PlanetaryConditions.L_PITCH_BLACK; }
/** Fighter Mode **/ public void setWhoFirst() { whoFirst = Compute.randomInt(500); }
/** * Gives a normal distributed Randomvalue, with mediumvalue from 0 and a * Varianz of factor. * * @param factor varianz of of the distribution. * @return Random number, most times in the range -factor .. +factor, at * most in the range of -3*factor .. +3*factor. */ private static int normRNG(int factor) { factor++; return (2 * (Compute.randomInt(factor) + Compute.randomInt(factor) + Compute .randomInt(factor)) - 3 * (factor - 1)) / 32; }
/** * randomly select gender * * @return true if female */ public boolean isFemale() { return Compute.randomInt(100) < percentFemale; }
public static boolean rollProbability(int prob) { return Compute.randomInt(100) <= prob; }
public static int generateRandomExp() { int roll = Compute.randomInt(100); if (roll < 20) { // 20% chance of a randomized xp return (Compute.randomInt(8) + 1); } else if (roll < 40) { // 20% chance of 3 xp return 3; } else if (roll < 60) { // 20% chance of 2 xp return 2; } else if (roll < 80) { // 20% chance of 1 xp return 1; } return 0; // 20% chance of no xp }
public void setWhoFirst() { whoFirst = Compute.randomInt(500); }
/** * Helper function that deploys the given units off board a random distance 1-2 boards in a random direction * @param entityList */ private static void deployArtilleryOffBoard(List<Entity> entityList) { OffBoardDirection direction = OffBoardDirection.getDirection(Compute.randomInt(4) + 1); int distance = (Compute.randomInt(2) + 1) * 17; for(Entity entity : entityList) { entity.setOffBoard(distance, direction); } }
public static Clan randomClan(int year, boolean homeClan) { ArrayList<Clan> list = new ArrayList<Clan>(); for (Clan c : allClans.values()) { if (year > 3075 && homeClan != c.homeClan) { continue; } if (c.isActive(year)) { list.add(c); } } return list.get(Compute.randomInt(list.size())); }
public static Date getBattleDate(GregorianCalendar c) { GregorianCalendar calendar = (GregorianCalendar)c.clone(); calendar.add(Calendar.DATE, Compute.randomInt(7)); return calendar.getTime(); }
public Clan getRivalClan(int year) { ArrayList<Clan> rivals = getRivals(year); int roll = Compute.randomInt(rivals.size() + 1); if (roll > rivals.size() - 1) { return randomClan(year, homeClan); } return rivals.get(roll); }
private Entity getRandomUnmovedEntity() { List<Entity> owned = getEntitiesOwned(); List<Entity> unMoved = new ArrayList<>(); for (Entity e : owned) { if (e.isSelectableThisTurn()) { unMoved.add(e); } } return unMoved.get(Compute.randomInt(unMoved.size())); }
public int getRandomTrooper() { Vector<Integer> activeTroops = new Vector<Integer>(); for (int loop = 1; loop < locations(); loop++) { if (isTrooperActive(loop)) { activeTroops.add(loop); } } int locInt = Compute.randomInt(activeTroops.size()); return activeTroops.elementAt(locInt); }
public Date getRandomDayOfMonth(GregorianCalendar cal) { GregorianCalendar calendar = (GregorianCalendar)cal.clone(); calendar.set(Calendar.DAY_OF_MONTH, Compute.randomInt(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) + 1); return calendar.getTime(); }
protected int modifyInjuryTime(Person p, int time) { // Randomize healing time int mod = 100; int rand = Compute.randomInt(100); if(rand < 5) { mod += (Compute.d6() < 4) ? rand : -rand; } return Math.round(time * mod * p.getAbilityTimeModifier() / 10000); }
T randomItem() { if (isEmpty()) { return null; } int random = Compute.randomInt(lastKey()) + 1; return ceilingEntry(random).getValue(); } }
/** Called when creating a new injury to generate a slightly randomized healing time */ public static int genHealingTime(Campaign c, Person p, InjuryType itype, int severity) { int mod = 100; int rand = Compute.randomInt(100); if(rand < 5) { mod += (Compute.d6() < 4) ? rand : -rand; } int time = itype.getRecoveryTime(severity); if(itype == InjuryTypes.LACERATION) { time += Compute.d6(); } time = Math.round(time * mod * p.getAbilityTimeModifier() / 10000); return time; }