More than one random value/seed?

Hello, everyone! I'm a little rusty on coding in Arduino as I have not done it in quite some time. I'm making some code for a lightbulb that randomly flickers (Using PWM). Now I don't want this to just constantly randomly flicker, I want it to have some random amount of delay between its flickers and I want it to also complete the flicker loop a random amount of times before running the delay.

The first tidbit of the following code is just setup, most of the actual magic happens in the infinite loop.
What I want to happen:
1.Defines loops as a value between 5 and 11 (amount of times loop will loop until continuing on to next code segment)
2. Defines flickdelay as a value between 500 and 5001 (amount of "break time" where the bulb returns to normal between each flicker in milleseconds)
3. Begins a segment of code that loops the "flicker code" 'loops' amount of times.
4. After the code is looped 'loops' amount of times it continues on to a delay of 'flickdelay'
5. Rinse and repeat.

The "Flicker Code" seems to work fine but when I run it, it just constantly flickers.

Broken code:

int ledPin =  0;
int ledState[6];
long loops;
long flickdelay;
long randNumber;
int i;
int b;
int c;
int d;

void setup() {
pinMode(ledPin, OUTPUT);
ledState[0] = random(20, 201);
ledState[1] = random(20, 201);
ledState[2] = random(20, 201);
ledState[3] = random(20, 201);
ledState[4] = random(20, 201);
ledState[5] = random(20, 201);

void loop(){
loops = random(5, 11);
flickdelay = random(500, 5001);
int b = loops;
   while (b > 0) {
     analogWrite(ledPin, ledState[i]);     
     randNumber = random(-70, 71);          
     ledState[i] += randNumber;              
     if (ledState[i] > 200) {                
      ledState[i] = 200;                     
     if (ledState[i] < 10) {
     ledState[i] = 10;
     if (b == 1) {

(Credit to 'GreatScott' for the original "flickering" code.)


Could it be the italics? The compiler hates italics. Why don't you read the sticky thread on how to use this forum and learn how to post code correctly so that doesn't happen. You know, the tendency to read the docs first and write second is what separates the wheat from the chaff in coders.

I do admit I have a tendency to skim because, well you can't read everything you come across, and that post just seemed like it was telling you how to register and get started. I did look for a code cite button but couldn't find one as normally it isn't the very first button on the left. Anyhow, the issue is fixed, It really wasn't that big of a problem as the text was still readable and the point was still understood. I'm not looking to become wheat anytime soon on this subject, I'm just trying to understand how to fix my utter stupidity when it comes to C.

And for the record, they should totally make compilers accept italics because that would be absolutely amazing on the eyes.

Strange code :wink:

  while (b > 0) {

You never decrement 'b', so if 'b' is greater than 1 (which it always is as it's a copy of 'loops' which has a minimum of 5), you're forever stuck in there.

You also never change 'i' so you only use the first element of the array and could just as well have used a non-array type variable.

Further, if you ever manage to get out of the while loop, 'b' will be 0 and hence the if at the end of the loop() will never evaluate to true.

Thank you very much for the pinpoints!