I would like to create a set of random natural numbers that resemble a Gaussian distribution. The reason I want natursl numbers is because I would like to give these numbers as pwm values for lighting an led
I found this library which can generate a set of random numbers from a Gaussian.
would making these numbers integers after getting the distribution be my best bet?
Ask 10 programmers about random, and you get 100 opinions
This topic might get flooded with everyone talking about random and what they think is best. In the end, the Arduino random() function which uses the GCC compiler random is not so bad, it pretty evenly distributed.
Sure, you can use that Gaussian library and convert the value to a 0...255 integer for the PWM.
Why do you need something sophisticated for just a led ?
If you want a certain visual effect, then there are easier ways to implement a curve.
Did you know that the human eye sees brightness with almost a 10log curve ? That is a very steep curve. Perhaps what you have in mind will be visually not the same.
At Github I have a Fun with millis page. The examples "millis_soft_pulsating_led.ino" and "millis_led_heartbeat.ino" have a curve. Click on the blue text for the sketch, use the green button for the simulation in Wokwi.
I'm thinking about a random, going through a Gaussian curve, and then through a 10log curve for the human eye.
Hi thanks for the reply? I thought the random() function generates values from a uniform distribution? The experiment needs a set of values chosen from a Gaussian distribution. No i dont want to go through in an increasing order. I would like to generate an array which is drawn from some gaussain distribution
No. But what i wanted to know if there is a better way. Generating a Gaussian distribution from a set of finite values is impossible. I just want to be close to a Gaussian as possible. Thanks for the reply
Identical numbers are fine. I am interested in getting fluctuations of light levels around some mean value. I actually just found the Gaussian library link just before posting this question. I also wanted to know if the values I generated can be saved to the pc for analysis purposes? Or do I need an SD card for this purpose.
Regarding the requirement. I am interested in learning the specific patterns of changes in light that cause responses from neurons in the retina. My LED will be my light source. Hope this helps
True, but using summation, it is trivial to generate a reasonable approximation to a Gaussian distribution from the uniform distribution.
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
int rg=0;
// generate pseudo-Gaussian distribution with mean 0.0 and spread of +/- 1.0
for (int i=0; i<10; i++) rg+=random(1001);
Serial.println((rg-5000)/5000.0);
}
Thanks. I will check this out as well. Thanks for the help. I can just try to plot it out and check how it looks. How would I save the numbers that have been generated to a file. Does that work using the Serial.println command?