It looks like dead loop when it is running on linux system.(adsbygoogle = window.adsbygoogle || []).push({});

It works perfectly in windows.

Code (Text):

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define NF 10 //total number of data.

/* function prototypes */

double gaussian( void );

int

main()

{

int i;

double *ave;

srand(2050);

if(! (ave = malloc( NF * sizeof(double))) )

printf("memory error \n");

for(i=0;i<NF;i++)

ave[i]=gaussian();

for(i=0;i<NF;i++)

printf("%e, ", ave[i]);

free(ave);

}

double

gaussian( void )

{

static int useold = 0;

static double old;

if ( useold ) {

useold = 0;

return old;

} else {

double x, y, r2, norm;

int j;

double RAND;

do {

j=rand();

RAND=j*1.0/32767;

x = 2.0*RAND - 1.0;

j=rand();

RAND=j*1.0/32767;

y = 2.0*RAND - 1.0;

r2 = x*x + y*y;

} while ( r2 >= 1.0 || r2 == 0.0 );

norm = sqrt( -2.0*log( r2 )/r2 );

old = x*norm;

useold = 1;

return y*norm;

}

}

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# The code work in windows system but does not work in linux

**Physics Forums | Science Articles, Homework Help, Discussion**