[Rd] Problem with rnorm ?

Tong Wang wangtong at usc.edu
Sat May 12 02:19:31 CEST 2007


Hi, 
    I couldn't get the rnorm() work right in C, for example, the following code produce strange results.

#include <stdio.h>
#include <Rmath.h>

int main(void){
  double x[3];
  for(int i=0;i<3;i++)  x[i]=rnorm(0,1);
  printf("%lf,%lf,%lf",x[0],x[1],x[2]);
  return 0;
}

output :   -8.773321,-8.773321,-8.773321
compiling script:   gcc -std=gnu99  -Wall -IC:/PROGRA~1/R/R-24~1.1/include test.c -LC:/PROGRA~1/R/R-24~1.1/bin -lR -o test

Could someone tell me what's wrong with my code ? Thanks a lot.



More information about the R-devel mailing list