Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Random-numbers/C/random-numbers.c
Normal file
22
Task/Random-numbers/C/random-numbers.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
double drand() /* uniform distribution, (0..1] */
|
||||
{
|
||||
return (rand()+1.0)/(RAND_MAX+1.0);
|
||||
}
|
||||
double random_normal() /* normal distribution, centered on 0, std dev 1 */
|
||||
{
|
||||
return sqrt(-2*log(drand())) * cos(2*M_PI*drand());
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
double rands[1000];
|
||||
for (i=0; i<1000; i++)
|
||||
rands[i] = 1.0 + 0.5*random_normal();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue