10¸¸¹ø randomÀ¸·Î »ý¼ºÇؼ
symbol.txtÆÄÀÏ·Î ÀúÀåÇÏ·Á°íÇϴµ¥..
À߸øµÈ Á¡ÀÌ ¹ºÁö ¸ð¸£°Ú¾î¿ä.
txt.ÆÄÀÏÀÌ »ý¼ºÀÌ ¾ÈµÇ¿ä¤Ð¤Ì¤»¤»
#include <stdio.h>
#include <math.h>
#include <Windows.h>
double gaussianRandom(double average, double stdev);
int main(void) {
srand(GetTickCount());
for (int i = 1; i <= 100000; i++)
// Æò±ÕÀº 0 ÀÌ°í, Ç¥ÁØÆíÂ÷´Â 1 ÀÇ °æ¿ì
printf("%.17f\n", gaussianRandom(0, 1));
return 0;
}
double gaussianRandom(double average, double stdev) {
double v1, v2, s, temp;
do {
v1 = 2 * ((double) rand() / RAND_MAX) - 1; // -1.0 ~ 1.0 ±îÁöÀÇ °ª
v2 = 2 * ((double) rand() / RAND_MAX) - 1; // -1.0 ~ 1.0 ±îÁöÀÇ °ª
s = v1 * v1 + v2 * v2;
} while (s >= 1 || s == 0);
s = sqrt( (-2 * log(s)) / s );
temp = v1 * s;
temp = (stdev * temp) + average;
return temp;
{
int temp;
FILE*Gaussianpdf;
Gaussianpdf = fopen("symbol.txt", "w+");
fprintf(Gaussianpdf,"%f|n",temp);
fclose(Gaussianpdf);
}
}
Àâ´ã | 1422¸íÀÌ Àоú¾î¿ä. 18.117.229.92