Generate random string in an array

I'm trying to make a Fortnite drop spot chooser (one that will take in a bunch of values in an array, and will give a random one), and I keep getting faced with a blank LCD screen.

#include <LiquidCrystal.h>
const char* location[]={"Breakwater Bay", "The Citadel", "Shattered Slabs", "Anvil Square", "Frenzy Fields", "Faulty Springs", "Slappy Shores", "Brutal Bastion", "Lonely Labs"};
const char* str = location[randomSeed(9)];

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
}

void loop() {
lcd.print(str);
lcd.setCursor(0, 1);

}

Welcome to the forum

const char* str = location[randomSeed(9)];

You have confused the randomSeed() function with the random() function

Try something like this:

// need to know the number of elements in location[]
const char* location[9]={"Breakwater Bay", "The Citadel", "Shattered Slabs", "Anvil Square", "Frenzy Fields", "Faulty Springs", "Slappy Shores", "Brutal Bastion", "Lonely Labs"};

void setup() {
  Serial.begin(115200);

  for (int i=1; i<5; i++)
  Serial.println(location[random(0,9)]); //generate index 0 to 8
}

void loop() {
}

Choosing at random has to be done in the flow of your program.

Even if what you wrote worked, it would not continue to serve up random things from the array.

Try

void loop() {
  lcd.print(location[random(8)]);
  lcd.setCursor(0, 1);

  delay(1777);
}

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.