random integers to string arrays

PeterH,

This method is close to working. I can get the X value to print in there, but the Y value seems to be chopped to either a 0 or -1.

/*
Test program to convert random integers into strings commands to send to Stepper Control Board.
 
*/

//******************Constants***********


//******************Variables***********



//****************Function Prototypes******


//***************Setup******************************
void setup() {
  Serial.begin(9600);
  randomSeed(analogRead(0));
  
  
}

//*************Main Program Loop************************
void loop() {

long randNumber_X1 = random(-10000, 10001);
long randNumber_Y1 = random(-10000, 10001);
long randNumber_X2 = random(-10000, 10001);
long randNumber_Y2 = random(-10000, 10001);

Serial.print(randNumber_X1);
Serial.print(" ");
Serial.println(randNumber_Y1);

 
 const int LEN=20; // pick a number big enough to hold your longest command string + 1
 char command[LEN];
 sprintf(command, "%dX%dYG", randNumber_X1, randNumber_Y1);
 Serial.println(command);
 
}
//*********************FUNCTIONS***************************

//**************************************************************************

And the Serial Monitor output is below. The first line just prints the random numbers, the second is the sprintf conversion. Any clue as to whats up?

8899 -3632
8899X0YG
4295 -5583
4295X0YG
-2445 -3267
-2445X-1YG
-5280 -9285
-5280X-1YG
342 -2815
342X0YG
-5991 -3474
-5991X-1YG