From 45faf97cea0a640992000d03da3753705808ee3c Mon Sep 17 00:00:00 2001 From: Rui Hu Date: Wed, 13 Mar 2024 12:30:58 +0800 Subject: [PATCH] Add more randomness to the answer --- .../java/com/cleverthis/interview/padlock/PadlockImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/padlock-impl/src/main/java/com/cleverthis/interview/padlock/PadlockImpl.java b/padlock-impl/src/main/java/com/cleverthis/interview/padlock/PadlockImpl.java index d6c3de6..30614c2 100644 --- a/padlock-impl/src/main/java/com/cleverthis/interview/padlock/PadlockImpl.java +++ b/padlock-impl/src/main/java/com/cleverthis/interview/padlock/PadlockImpl.java @@ -45,7 +45,7 @@ public class PadlockImpl { * Create a padlock instance. * * @param numpadSize The number of buttons on the numpad of this lock. - * @param debug Will skip sleep if is true + * @param debug Will skip sleep if is true */ PadlockImpl(int numpadSize, boolean debug) { this.debug = debug; @@ -55,7 +55,9 @@ public class PadlockImpl { List answer = new ArrayList<>(numpadSize); for (int i = 0; i < numpadSize; i++) answer.add(i); - Collections.shuffle(answer); + for (int i = 0; i < numpadSize / 2; i++) { + Collections.shuffle(answer); + } this.correctPasscode = answer.toArray(new Integer[0]); }