/** * Returns a variant number between 0 (inclusive) and maxVariant (exclusive). Use this method to * get the next variant of a question in sequence. For the first attempt it returns a random * variant and for the repeat attempts it returns next variants in sequence, when the last variant * is reached it cycles back to the beginning. * * @param maxVariant * @return variant number */ public int getNextVariant(int maxVariant) { // Passing false for the 'incrementSeed' parameter to get the same // random number generator for all question attempts. Random r = getRandom(getClass().getName(), false); if (r instanceof NotSoRandom) { // If it is an instanceof NotSoRandom that means variant is fixed // for testing, do not increment the variant return r.nextInt(maxVariant); } return (r.nextInt(maxVariant) + ip.getAttempt() - 1) % maxVariant; }
public void genSeed(ActionEvent e) { long seed = 0; boolean redo = false; do { redo = false; String seedString = JOptionPane.showInputDialog( this, "Enter a number:", Long.toString(rand.nextLong(), 36) // "Random Seed", JOptionPane.QUESTION_MESSAGE ); if (seedString == null) return; try { seed = Long.parseLong(seedString, 36); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(this, "Use only letters and numbers, max 12 characters."); redo = true; } } while (redo); genSeed(seed); }
public void genRandom() { genSeed(rand.nextLong()); }