function of type integer array

hello!
i want to randomize an array of 8 integer numbers.
an elegant way would be a function from the type of an array of integer numbers which returns a randomized array.

in this case i could call the randomize function easily:
ExistingArray = RandomFunction;

i just right now do not remember how to do this.
i tried a declaration in the style of

int[8] randomize(int k){
  randomSeed(millis());
  for (int i=0; i<k; i++){
    randomize[i] = random(0,1);
  }
  return randomize;
}

but this is not quite correct :wink:

It's probably easier to pass the array as a parameter into the function - any values you assign to it within the function will carry over to the calling function. If you want to return an array from a function, you start needing to deal with allocation and deallocation of memory.

You might find something of use in this approach too.

http://www.arduino.cc/playground/Main/RandomHat

I would be very grateful if forum gurus could post a short piece of code that does send an array to a function, and then return a modified array back to the calling routine. That is, similar to the code provided by haesslich (but which works correctly).

i.e. a piece of code like this but which has correct syntax:-

void(loop) {
...
int sourceValues[6] = {0,1,2,3,4,5};
...
FunctionWhichOperatesOnSourceValueArray(sourceValues);
...
}

int[6] FunctionWhichOperatesOnSourceValueArray(int[6]) {
byte counter = 0;
for (counter = 0; counter < 6; counter ++) {
array(counter)++
}
return array somehow
}

Regards,
TB

You don't actually need to return the array from the function. Just modify the one that got passed in, and the changes will be reflected in the calling function.

E.g.

int pins[] = { 2, 3, 4 };

void incrementArray(int arr[], int length)
{
  for (int i = 0; i < length; i++) {
    arr[i] = arr[i] + 1;
  }
}

void setup()
{
  incrementArray(pins, 3);
  // now pins is { 3, 4, 5 }
}

void loop()
{
  // ...
}