Can't get random string from array

Hi!
I'm wrinting a C# application to analyze a car CAN bus's traffic. I know what kind of messages I can get from a real car, so I decided to use Arduino shield as a car's CAN bus simulator.
Here's the code:

const int ARRAY_LENGTH = 31;

String dummyCommands[] = { 
    "can0  33A   [8]  00 00 00 00 00 00 00 00",                                                                     
    "can0  415   [8]  00 00 C4 FB 0F FE 0F FE",                                                                   
    "can0  346   [8]  00 00 00 03 03 00 C0 00",                                                                      
    "can0  348   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  167   [8]  72 7F FF 10 00 19 F8 00",                                                                      
    "can0  3E0   [8]  00 00 00 00 80 00 00 00",                                                                      
    "can0  167   [8]  72 7F FF 10 00 19 F7 00",                                                                      
    "can0  34E   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  358   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  3A4   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  216   [8]  00 00 00 00 82 00 00 00",                                                                      
    "can0  3AC   [8]  FF FF FF FF FF FF FF FF",                                                                      
    "can0  415   [8]  00 00 C8 FA 0F FE 0F FE",                                                                      
    "can0  083   [8]  00 00 00 00 00 01 7E F4",                                                                      
    "can0  2FD   [8]  D4 00 E3 C1 08 52 00 00",                                                                      
    "can0  3BC   [8]  0C 00 08 96 01 BB 27 00",                                                                      
    "can0  167   [8]  72 7F FF 10 00 19 F7 00",                                                                      
    "can0  3BE   [8]  00 20 AE EC D2 03 54 00",                                                                      
    "can0  333   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  42A   [8]  D6 5B 70 E0 00 00 00 00",                                                                      
    "can0  42C   [8]  05 51 54 00 90 46 A4 00",                                                                      
    "can0  33B   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  42E   [8]  93 00 00 E1 78 03 CD 40",                                                                      
    "can0  42F   [8]  7D 04 00 2E 66 04 01 77",                                                                      
    "can0  167   [8]  72 7F FF 10 00 19 F7 00",                                                                      
    "can0  3E7   [8]  00 00 00 00 00 00 00 00",                                                                     
    "can0  216   [8]  00 00 00 00 82 00 00 00",                                                                      
    "can0  415   [8]  00 00 CC F9 0F FE 0F FE",                                                                      
    "can0  3A5   [8]  00 00 00 00 00 00 00 00",                                                                      
    "can0  3AD   [8]  FF FF FF FF FF FF FF FF",                                                                      
    "can0  50B   [8]  1E 12 00 00 00 00 00 00"
};

void setup() {
  Serial.begin(9600);
}

void loop() {
  int index = random(0, ARRAY_LENGTH);
  Serial.print(index);
  String result = dummyCommands[index];
  Serial.print(result);
  Serial.println("<<");
  delay(1000);
}

All I need from it is to send random string over a serial port every second.
But I always get empty string as a result. So my serial monitor gives me something like this:

20<<
21<<
9<<
11<<
27<<
2<<
16<<
20<<
20<<
0<<
27<<
18<<
30<<
9<<
17<<
15<<
6<<

What am I getting wrong here? :-\

What am I getting wrong here?

You are using the dreaded String class. There is no reason for that. Change String to char *, and report the new results.

I've just found the problem. Everything is correct in my code the problem was that I first copied this code from Visual Studio on Windows and it added its line endings. So I have re-typed everything in Arduino IDE by hand and it works now :smiley:

You are using the dreaded String class. There is no reason for that. Change String to char *, and report the new results.

Thanks for the advice, I'll keep it in mind =)

Hello, you can save a huge amount of memory if you did something like this, instead of using strings :slight_smile:

guix:
Hello, you can save a huge amount of memory if you did something like this, instead of using strings :slight_smile:

try generate...c# random string