old memories/physics

t distribution and GSL random number generator

citadel 2007. 7. 2. 22:57
t distribution with large degrees of freedom is the same as Normal (Gaussian) distribution with mean 0 and standard devitation 1 approximately.
  • normal[x_] := PDF[NormalDistribution[0, 1], x]
  • t[x_, nu_] := PDF[StudentTDistribution[nu]], x]
  • Plot[{normal[x], t[x, 3], t[x, 6], t[x, 20]}, {x, -6, 6},  PlotStyle -> {Black, Gray, Blue, Red}]
  • Five real random numbers x0 from the Gaussian distribution (0,1):

  • Five real random numbers x1 from the Gaussian distribution (mu,sigma) :
  • There is the following relation : x1 = x0*sigma + mu

Therefore, from a real random number from t distribution random number generator with nu, I can get the random magnetic field strength B_t as following:
,where t_random is generated by gsl_ran_tdist function as


In the random_t_distribution function, I used a sort of random number generator in order to get a random seed. The original random number generator, which is based on /dev/random, is shown in Advanced Linux Programming Chapter 6. I modified it as following:

Secure Programming Cookbook for C and C++ (11.3 Using the Standard Unix Randomness Infrastructure) is also useful reference book on the web.