Hi there,
I want to create a lightning storm cloud, with just three ordinary leds, as attached GIF shows. I found this idea on the internet, but code was not available, so I want to do one by myself.

On my code, one led works fine, but I cannot make three leds work independent.
Thanks in advance.
PS. Code is deleted here because I am updating it on my last response.
On my code, one led works fine, but I cannot make three leds work independent.
All 3 are working, just not "independently", right?
The microcontroller can only to one thing at a time, and it can't do anything during delay(). (Except it will continue to run a PWM output.) If you put delays in a function you can't get out of that function to run another function until the delays are up and that function exits.
Take a look at the Blink Without Delay example and look at the link at that to of the forum about doing several things at the same time.
And, simplify your code! It looks like you wrote an awful lot of code before you figured-out that your basic concept wasn't working... Maybe try 2 LEDs with independent timers, and then when that works, 3 LEDs, and add the randomness and the dimming last. Take it one SMALL step at a time.
Yeah, you're right, I made it in a hurry. Well, I got this, could you please tell me whether I am in the right path?
I uploaded new code.
projeto_cristian.ino (610 Bytes)
I'm not in a place where I have code readily available, but I did something similar wherein I created an array to store a sort of brightness value for each LED. Initially all the LEDs are set to a random blue value and those are stored. In my loop I read the array value. If it's an even number, I increase it by two, if it's odd, I decrease by two, then set all the colors. A high and a low value are determined so they bounce back the opposite direction for very subtle fading or breathing effect. Then, randomly 1 out of every hundred iterations or so, I run a function that produces bright flashes like lightning, before returning the previously stored value.
It's quite effective. The kicker in getting it to work for me was first to write and read from the array, then the use even or odd to determine what happens next in the loop. That way they aren't all at a constant brightness. I use something similar to simulate candles flickering in the windows of a Christmas village display.
I'll post up the code later if you're interested. You can also take a look here:
http://codepen.io/jedimasta/pen/VKVWQL
It's javascript I created to simulate the neopixel code so I could build patterns outside of the arduino itself. It might help.
You -could- get it to work with short delay() and changing none, some, or all of the pins between each delay() but without a good bit of control code or extensive data modelling it would get from boring to predictable before long, kind of like that GIF.
DVDdoug points you down a trail that doesn't just lead to a better model but also to automating all kinds of things and just writing smaller more efficient code in general.