I’ve been incorporating LED to my art and FastLED is a great resource. My first large works used a highly modified NoisePlusPalette with multiple random palettes, random scales, and random speeds. I started making some smaller works and may have made an false assumption about “random”.
Do call ups for random occur as the program loops in the physical Arduino or does it only occur once when it is compiled on my PC and uploaded to the Arduino?
The reason I ask is that I noticed that if I start two separate small works at the same time that use the same sketch, I get very similar animations. It might be because my range random(x,x) is too confined, or do I need to bump up to a raspberry pi or something else to get randomness on each turn of the loop?
Arduino’s random() is really just a ‘pseudo-random’. Each time it resets, it starts the same sequence of numbers again as it’s using the same seed. Two or a hundred Arduinos will do the same exact thing. If you want them to be truly random, you need to seed it with some noise by using randomSeed(analogRead(0)); (assuming analog pin0 isn’t connected to anything.)
And actually, even that isn’t truly random. For something that’s even more random you’d want to consider adding perhaps a geiger counter.
Count the clicks, seed another random number to that, etc., etc.
I haven’t tried it, but I was thinking about something like
randomSeed(now())
That would depend on it reading the time from the computer when you first compile it and won’t retain it after a reboot once it’s been disconnected from the computer. Or, you need to add an RTC. But why do that if you have an available analog pin? Just read the noise from that.
The documentation page on (analogRead(0)) shows an example of the line in the Setup. I assume this will generate a single repeating random loop every time upon start up (correct me if I’m mistaken). Is it possible to put (analogRead(0)) in a loop and get different randomness on each cycle of the loop?
random() generates a stream of (random) numbers so that each cycle has a different number. However the seed value is always the same. So when you restart the program (by means of power cycling the unit), the stream starts over with the same exact set of numbers. By introducing analogRead(0) as the seed, you are giving it a different seed value with each power cycle so the stream of numbers itself will not be the same. Has nothing to do with individual cycles as those just read the stream itself.
However, if you must, you can re-introduce a new seed anywhere in your program, however you’re just wasting clock cycles now. It only needs to be done once.