My question is: how to create a random task with a given number (4-8) of tests?
The task is created from tests (see code below).
Tests are attributes of a class Challengeconstructed from an enumeration, and EnumMap.
Therefore, when I get a random number in the main (e.g. r.nextInt(4) + 4;), I will create this number of tests to call as follows
Weapons = 25;
Hacking = 32;
Vehicle = 34;
Speed = 56;
So, for 1 Challenge, I do not need all the tests, only some of them. But I still need the opportunity to choose from them randomly (4-8).
How can I generate these random objects Challengewith a given number of attributes (and their values)? So basically some of them, from ALL of them.
? ?
:
import java.util.*;
public class Challenge {
Random r = new Random();
public static enum Trial {
DRIVE, VEHICLE, ACCURACY, WEAPONS, REFLEX, STRATEGY, CHARISMA, HACKING, SPEED, STEALTH;
}
Map<Trial, Integer> challenge = new EnumMap<Trial, Integer>(Trial.class);
public Challenge() {
challenge.put(Trial.DRIVE, r.nextInt(100) + 25);
challenge.put(Trial.VEHICLE, r.nextInt(100) + 25);
challenge.put(Trial.ACCURACY, r.nextInt(100) + 25);
challenge.put(Trial.WEAPONS, r.nextInt(100) + 25);
challenge.put(Trial.REFLEX, r.nextInt(100) + 25);
challenge.put(Trial.STRATEGY, r.nextInt(100) + 25);
challenge.put(Trial.CHARISMA, r.nextInt(100) + 25);
challenge.put(Trial.HACKING, r.nextInt(100) + 25);
challenge.put(Trial.SPEED, r.nextInt(100) + 25);
challenge.put(Trial.STEALTH, r.nextInt(100) + 25);
}
List<Trial> keys = new ArrayList<Trial>(challenge.keySet());
Trial randomKey = keys.get(r.nextInt(keys.size()));
Integer value = challenge.get(randomKey);
}