CodingNic

Generator Features

Add Dice Mode

Generator Features 15 min read

Add Dice Mode

Add Dice Mode

Dice Mode should change the generator’s settings, not create a second password algorithm.

1. Pick a random length

Use the secure helper from Module 2:

javascript
const min = Number(lengthRange.min);
const max = Number(lengthRange.max);
const length = min + secureRandom(max - min + 1);
lengthRange.value = length;
lengthValue.textContent = length;

2. Randomize the character options

Use the existing inputs derived from sets:

javascript
characterInputs.forEach((input) => {
  input.checked = secureRandom(2) === 1;
});

After this loop, check whether every option is off. If so, turn on one randomly selected input. The important rule is that Dice Mode must always leave a usable configuration.

3. Reuse the generator

Once the random settings are in place, call:

javascript
generatePassword();

Do not duplicate the generation algorithm. Dice Mode is only a configuration shortcut.

4. Connect the button

Attach the sequence to the existing diceButton click event.

Test

Press Dice Mode repeatedly. Confirm that length/options can change, a new password appears immediately, and the password still follows the selected configuration.

Checkpoint

Dice Mode now creates a surprise configuration while keeping generatePassword() as the single source of truth for password generation.