box muller algorithm

Hello All,
As Im new to this forum and the arduino community, I want to understand the box muller algorithm.
I would like to generate a set of random numbers on my led cube and generate the probability distribution.
I uploaded the code given above and I dont see any data in the serial monitor!
Am I in the right path ? Please Help?

Thanks!
Shravan.

Did you select 9600 baud at the bottom right of the serial monitor?

PaulRB:
Did you select 9600 baud at the bottom right of the serial monitor?

YES, I did!

Works for me on a Nano, although I made two changes to the loop function to make the output easier to read.

void loop(void)
{
  double r1, r2;
  box_muller(2, &r1, &r2);
  if(r1 >= 0)Serial.print(" ");
  Serial.print(r1);
  Serial.print("; ");
  if(r2 >= 0)Serial.print(" ");
  Serial.println(r2);
  delay(100);
}

Pete

Thanks for your reply!

But I dont see anything on my serial monitor even after changing the code. I am using a UNO board with baud set to 9600.

Also, &r1 and &r2 takes the two inputs for computation as sigma is set to 2 as per the code. So in this case how r1 and r2 gets the values to compute?

I mean should we provide the inputs from a knob / keyboard?

I tried to input the r1 and r2 values from keyboard ranging between 0 and 1 and clicked send on the serial monitor. When I clicked, the Rx pin is receiving the data from keyboard as it is blinking for the input data..But there is no output seen even after the autoscrolling is turned ON!

Below is the code for your perusal!
void box_muller(double sigma, double *r1, double *r2);

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
randomSeed(analogRead(0));

}

void loop() {
// put your main code here, to run repeatedly:
double r1,r2;
box_muller(2, &r1, &r2);
if(r1 >=0) Serial.print(" ");
Serial.print(r1);
Serial.print("; ");
if(r2 >= 0)Serial.print(" ");
Serial.println(r2);
delay(100);
}

void box_muller(double sigma, double *r1, double *r2)
{
double
u1,u2,
v1,v2,s,
z1,z2;

for(;;){
v1 = 2.0Lu1 - 1.0L;
v2 = 2.0L
u2 - 1.0L;
s = v1*v1 + v2 * v2;

if(s<= 1.0L && s != 0.0L)
break;

}

z1 = sqrt(-2.0L * log(s) / s) * v1;
z2 = sqrt(-2.0L * log(s) / s) * v2;

if(r1 != NULL) r1 = (z1sigma);
if(r2 != NULL) r2 = (z2sigma);

return;
}

I see the problem. There is a smiley in your code.

PaulRB:
I see the problem. There is a smiley in your code.

Bob Ross style coding. Happy little accidents.

(ps, OP, use code tags and you'll be smiley free.)

I got it! Thanx for your wonderful support!