Starter Kit Project 11: "LCD Crystal Ball"

Hello guys!

I did the Crystal Ball project today. It all works perfectly until I add a couple of lines to the code, these lines are to add a little more suspense before receiving a response.

Here's my code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;

void setup() {
  lcd.begin(16, 2);
  pinMode(switchPin,INPUT);
  lcd.print("Ask the");
  lcd.setCursor(0, 1);
  lcd.print("Crystal Ball!");
}

void loop(){
  switchState = digitalRead(switchPin);
  if (switchState != prevSwitchState){
    if (switchState == LOW){
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Contacting the");
      lcd.setCursor(0, 1);
      lcd.print("chance servers...");
      delay(100);
      lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print("Uploading");
      lcd.setCursor(0, 1);
      lcd.print("request...");
      delay(100);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Waiting for");
      lcd.setCursor(0, 1);
      lcd.print("reply...");
      delay(100);
      lcd.clear();
      reply = random(8);                            
      lcd.setCursor(0, 0); 
      lcd.print("The Ball Says:");
      lcd.setCursor(0, 1);
      switch(reply){
        case 0:
        lcd.print("Yes.");
        break;
        case 1:
        lcd.print("Most Likely");
        break;
        case 2:
        lcd.print("Certainly");
        break;
        case 3:
        lcd.print("Outlook good.");
        break;
        case 4:
        lcd.print("Unsure.");
        break;
        case 5:
        lcd.print("Ask again.");
        break;
        case 6:
        lcd.print("Doubtful.");
        break;
        case 7:
        lcd.print("No.");
        break;
      }
    }
  }
  prevSwitchState = switchState;
}

Anyway, the code follows a pattern when you run it, it prints "No.", "Most Likely" x2, "Certainly", etc..

I have tried moving the statements around but could not fix it, can anybody give me a hand?

Sorry for not using the appropriate format for the code, won't happen again.

I also adjusted the time in the delay to 1ms, the original was 1.5 sec.

You can edit your post to change the table tag to a code tag.

The random number generator is a PRNG. It will follow a pattern unless you give it something actually random to start with. The millisecond that the person pushed the button is properly random. Use that to seed the PRNG.

Thanks for the reply.
It seems that when I remove the arguments, it is in fact random. According to the book it does not need other arguments besides the 8 in the random(); argument.

I'll research your solution as soon as I can.

Thanks

MorganS:
You can edit your post to change the table tag to a code tag.

The random number generator is a PRNG. It will follow a pattern unless you give it something actually random to start with. The millisecond that the person pushed the button is properly random. Use that to seed the PRNG.

After reading random() - Arduino Reference, I believe what you're talking about is the randomSeed(); argument. Which I am not using. I also read the PRNG and according to both, a starting number is optional and by default 0.

Still haven't figured out what is going on. I'll try a couple of things.

rackomint:
After reading random() - Arduino Reference, I believe what you're talking about is the randomSeed(); argument. Which I am not using. I also read the PRNG and according to both, a starting number is optional and by default 0.

Still haven't figured out what is going on. I'll try a couple of things.

Nevermind, I got it, thanks.