Digital signal Processing C language------uniform distribution and Gaussian distribution random number

Source: Internet
Author: User
Tags random seed

Environment: qt5+vs2013 Compilation

One, evenly distributed

Double uniform (double a,double b,long int *seed)
A lower bound, Upper B, seed random seed.

Main.cpp

#include <QCoreApplication>#include<math.h>#include<stdio.h>#include<stdlib.h>#include<uniform.c>intMainintargcChar*argv[])    {Qcoreapplication A (argc, argv); DoubleB,c,x;inti,j; Long ints; DoubleUniformDouble,Double,Long int*); b=0.0; c=1.0; s=13579;  for(i=0;i<Ten; i++)    {         for(j=0;j<5; j + +) {x=uniform (b,c,&s); printf ("%13.7f", x); } printf ("\ n"); }    returna.exec ();}

Uniform.c

double uniform (double A,double B,longint *seed) {double  t; *seed=2045* (*seed) +1; *seed=*seed-(*seed/1048576) *1048576; t= (*seed)/1048576.0; t =a+ (b-a) *t; return (t);}

Second, Gaussian distribution

Double Gauss (double mean,double sigma,long int *s)
Mean positional parameters, Sigma scale parameters, seed random seed

Main.cpp

#include <QCoreApplication>#include<math.h>#include<stdio.h>#include<stdlib.h>#include<gauss.c>intMainintargcChar*argv[])       {Qcoreapplication A (argc, argv); inti,j; Long ints; DoubleX,mean,sigma; DoubleGaussDouble,Double,Long int*); Mean=0.0; sigma=1.0; s=13579;  for(i=0;i<Ten; i++)     {          for(j=0;j<5; j + +) {x=gauss (mean,sigma,&s); printf ("%13.7f", x); } printf ("\ n"); }    returna.exec ();}

Gauss.c

#include <uniform.c>DoubleGaussDoubleMeanDoubleSigmaLong int*s) {    inti; Doublex, y; DoubleUniformDouble,Double,Long int*);  for(x=0, i=0;i< A; i++) x+=uniform (0.0,1.0, s); X=x-6.0; Y=mean+x*Sigma; return(y);}

Uniform.c

double uniform (double A,double B,longint *seed) {double  t; *seed=2045* (*seed) +1; *seed=*seed-(*seed/1048576) *1048576; t= (*seed)/1048576.0; t =a+ (b-a) *t; return (t);}

Digital signal Processing C language------uniform distribution and Gaussian distribution random number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.