randomizing array values

So, i'm trying to assign random numbers to an array with blank values via a function. The issue is, while it complies and i can upload it onto my board, nothing happens. Keep in mind, i'm barely in my second week of reading up on and trying to understand code so try not to be too harsh. lol

it's not too long, but i'm just to build functional example because it helps me learn. it's ok if an int repeats i'm just trying to build a random array of values.

#include <FastLED.h>
#define NUM_LEDS 3
 const int totalArray = NUM_LEDS -1;
 const int sparkleArray[totalArray];
CRGBArray<NUM_LEDS> leds;

void setup() { 
  Serial.begin(9600);
  FastLED.addLeds<WS2812B,3, GRB>(leds, NUM_LEDS); 
  }

void loop() {

defineSparkleLeds(totalArray, sparkleArray);

for(int i = 0; i <= totalArray; i++) {
  leds[sparkleArray[i]] = CRGB(75, 25, 10);
  FastLED.show();
  delay(2000);
  leds[sparkleArray[i]] = CRGB(0, 0, 0);
  FastLED.show();
  delay(1000);
}

}

int defineSparkleLeds(int totalArray, int sparkleArray[]) {
  for(int j = 0; j <= totalArray; j++) {
    int sparkleArray[j] = {random(0, totalArray)};
  }
return defineSparkleLeds;
}

Thanks for using code tags on your first post. It would be helpful if you could remember to perform Auto Format in the IDE before you post code.

const int totalArray = NUM_LEDS -1;
const int sparkleArray[totalArray];

Two things here. You have made sparkleArray one element shorter than the leds array. Is that what you wanted? Secondly, you made it const, which means you cannot change the values later. Normally, the compiler will complain if you make something a const and then try to assign to it later. But in your case, you haven't done that, because of another error.

int defineSparkleLeds(int totalArray, int sparkleArray[]) {
  for(int j = 0; j <= totalArray; j++) {
    int sparkleArray[j] = {random(0, totalArray)};
  }
return defineSparkleLeds;
}

Quite a few things wrong here. You made your function return an int. But when you call it in loop(), you discard (ignore) the return value. I suspect you should make this function's type void not int. Then you won't need the return statement (which is also wrong in itself, by the way).

Here's the most important error:

    int sparkleArray[j] = {random(0, totalArray)};

Putting int at the start of the line creates a new variable, so it does not assign to the array passed in as a parameter. The curly braces are also not required.

Thanks for all the input. I made the changes you suggested (including the auto format :smiley: ) and took out some variables and replaced them with numeric values and it works great now.

#include <FastLED.h>
#define NUM_LEDS 3
int sparkleArray[NUM_LEDS];
CRGBArray<NUM_LEDS> leds;

void setup() {
  Serial.begin(9600);
  FastLED.addLeds<WS2812B, 3, GRB>(leds, NUM_LEDS);
}

void loop() {

  defineSparkleLeds(sparkleArray);

  for (int i = 0; i <= 2; i++) {
    leds[sparkleArray[i]] = CRGB(random(0, 256), random(0, 256), random(0, 256));
    FastLED.show();
    delay(60);
    leds[sparkleArray[i]] = CRGB(0, 0, 0);
    FastLED.show();
    delay(60);
    Serial.print("int i: ");
    Serial.println(i);
    Serial.print("sparkle array: ");
    Serial.println(sparkleArray[i]);
  }

}

void defineSparkleLeds(int sparkleArray[]) {
  for (int j = 0; j <= 2; j++) {
    sparkleArray[j] = random(0, 3);
  }
}

took out some variables and replaced them with numeric values

That was a step backwards. You could do it like this:

for (int i = 0; i < NUM_LEDS; i++) {