読者です 読者をやめる 読者になる 読者になる

One Algorithm to Generate Gaussian Distribution in C

MD

#include <stdlib.h> #include <math.h> double gaussrand() { static double V1, V2, S; static int phase = 0; double X; if ( phase == 0 ) { do { double U1 = (double)rand() / RAND_MAX; double U2 = (double)rand() / RAND_MAX; V1 = 2 * U1 - 1; V2 = 2 * U2 - 1; S = </math.h></stdlib.h>…

Use of Macro Definitions to Simplify MD Code

MD

C supports the use of macro definitions that can simplify the code considerably. #define Sqr(x) ((x)*(x)) #define Cube(x) ((x)*(x)*(x)) #define VSub(v1, v2, v3) (v1).x = (v2).x - (v3).x, (v1).y = (v2).y - (v3).y The above definition will s…