[HELP] Random Number code not working as expected.

Hi all,
I’ve been working on this code for a while now, but I don’t quite understand why it is not working. It’s probably very simple, but any help would be very appreciated. Essentially, the UltraSound detector should show when something gets too close, make a buzzer beep 3 times, then display a random message on the LCD board. However, the board displays test 3 all the time, and does not change when the ultrasound detector detects something too close. any and all help would be appreciated! Thank you all!

#include “pitches.h”
#include “SR04.h”
#include <LiquidCrystal.h>

#define TRIG_PIN 12
#define ECHO_PIN 11

SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;
long randState;

LiquidCrystal lcd(16, 17, 18, 19, 20, 21);

void personFound() {
tone(8, NOTE_E5, 500);
delay(750);
tone(8, NOTE_F5, 500);
delay(750);
tone(8, NOTE_G5, 500);
delay(1500);
}

void setup() {
Serial.begin(9600);
delay(1000);
lcd.begin(16, 2);

}

void loop() {
a=sr04.Distance();
Serial.print(a);
Serial.println(“cm”);
randState = random(1,10);
if(a < 11) {
personFound();
randState = random(1,10);
if(randState = 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Test1”);
randState = random(1,10);
}
if(randState = 2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Test2”);
randState = random(1,10);
}
if(randState = 3) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Test3”);
randState = random(1,10);
}
}
delay(75);
}

The #1 classic C-newby error.

  if(randState = 1) {

To compare two values, use ==
To assign a value to a variable, use =

Before you post on the forum again, please read the forum guidelines in the sticky post. Your post above breaks a forum rule.

You must seed a random number generator otherwise it would produce the same results in every run of your sketch.