I'm trying to program a little puzzle with 4 push buttons and a servo mounted to a little box. There are led's and a buzzer for user feedback and eventually there will be a reed switch to detect if the lid of the box is open or not but essentially the user needs to work out the sequence of the 4 push buttons to get the servo to unlock the box.
I thought I had things cracked but there is a strange thing going on with my randomisation script.....
My intention is that on power up, the box is locked and a random sequence is generated (eg 1234 or 4231 etc).... this remains constant until the code is cracked then another random sequence is generated and so on....
At first glance, all seemed to be fine BUT I noticed that every time the arduino is powered up, it is the same sequence generated.... in fact the once these are cracked, the first 4 sequences are identical....
Here is the code for the function that is called to randomise the sequence.
void randomise(){
target[0]=random(1,5);
target[1]=random(1,5);
while(target[1]==target[0]){
target[1]=random(1,5);
}
target[2]=random(1,5);
while(target[2]==target[0]||target[2]==target[1]){
target[2]=random(1,5);
}
target[3]=random(1,5);
while(target[3]==target[0]||target[3]==target[1]||target[3]==target[2]){
target[3]=random(1,5);
}
}
If anyone can point out what I presume is an obvious school boy error, please let me know.
Dave