How do I populate an Array with 10 random number?

I want to populate an array with 10 slots with 10 random numbers. How would I do this? Can't find any tutorials anywhere for this but it seems like it'll be simple?

Do you know how to generate a single random number ?
Do you know how to write a for loop ?
What range of numbers is to go into the array ?
Are the numbers allowed to repeat within the 10 entries ?
If not then put the individual numbers in the array then swap 2 of them a random number of times

I know how to generate a random number.
I'm not too sure on the for loop. Idk how to format it?

for (randLed=led[0]; i < 9; led[0]++)
?

for (int x = 0; x < 10; x++)  //start with x at zero.  While x is less than 10 execute the code block and then increment x
  {
     Serial.println(x);
  }

You need to find an online C tutorial to learn such basic stuff

so for (int led[0]=randLed; led[0] < 10; led[0]++)
?
do I put led[0] starting with the first value in the array or do I put 9, the total amount of arrays?

An array with zero elements ?

Up there on the right, there's a drop-down. It can take you to the reference page, where the for loop is described in detail.

so
for (int led[9]=randLed; <= this is where I get confused. what do I put as the max ?

Now an array with nine elements?

Did you look at the reference page?

dude I've obviously looked at the reference page. No 10 elements arrays start from 0. I don't get this and it's making me feel like a complete idiot. So say I'm a complete idiot and just help me understand

The loop control is usually a single integer.

Work from there.

(It wasn't at all obvious that you'd looked at the for loop reference page)

Earlier in another thread you put a 0 in every element. Use the same approach but stick a random number in instead of the 0. Check that other thread.

You're trying to do all the work in the initial for statement. For loops don't work like that. The for part just loops. The work of setting values or printing things etc happens in the following code block.

Take UKHeliBob's for statement which is perfect for what you want. Then instead of the Serial.println() put in something that sets the xth element in your array to a random value (and I know you've used random values before).

If you're not sure how to do that then you need to look at how arrays are read and updated. Try https://www.arduino.cc/en/Tutorial/Arrays

Steve

this compiles but does nothing

int randLed;
int led[10];
int level;
void setup()
{
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(6,INPUT);
  pinMode(7,INPUT);
  pinMode(8,INPUT);
  pinMode(9,INPUT);

  Serial.begin(9600); 
  randomSeed(analogRead(0));
}


void loop()
{ randLed=random(2,6);
for (randLed=led[0]; led[9]< 10; led[0]++);
 digitalWrite(led[1], HIGH);
 delay(1000);
 digitalWrite(led[1], LOW);
 delay(1000);
 digitalWrite(led[2], HIGH);
 delay(1000);
 digitalWrite(led[2], LOW);
 delay(1000);
  
}

@formerlyknown IDK what any of that means...

The main reason it doesn't work is because you've ignored everything all of us have said.

Steve

UKHeliBob:

for (int x = 0; x < 10; x++)  //start with x at zero.  While x is less than 10 execute the code block and then increment x

{
    Serial.println(x);
 }




You need to find an online C tutorial to learn such basic stuff

so for this x would = led[10]?

or is it randLed=led[0];?

It does stuff.
Let's take a closer look

for (randLed=led[0]; led[9]< 10; led[0]++);

First time through loop, crt0 has already zeroed the led array for you, so randLed is zero. led [9] is also zero. Zero is less than ten, so increment led [0].
Zero is still less than ten, so increment led [0]

And so on.

slipstick:
The main reason it doesn't work is because you've ignored everything all of us have said.

Steve

I'm not ignoring anyone. I'm just not understanding and my brain is fried

TheMemberFormerlyKnownAsAWOL:
It does stuff.
Let's take a closer look

for (randLed=led[0]; led[9]< 10; led[0]++);

First time through loop, crt0 has already zeroed the led array for you, so randLed is zero. led [9] is also zero. Zero is less than ten, so increment led [0].
Zero is still less than ten, so increment led [0]

And so on.

I don't want randLed to be zero, I want whatever the random led chosen to be stored in array 0.

Did you read my #10?

premobowei:
I don't want randLed to be zero, I want whatever the random led chosen to be stored in array 0.

So, which side of the assignment operator (aka "=" sign) should led [ 0 ] be?

The compiler isn't a fairy.godmother - it doesn't know your wishes, it just does what you told it to do.