lundi 30 avril 2018

how can i create random number generator that follows t distribution? in python

how can i create random number generator that follows t distribution? with given mu, variance, and degrees of freedom

import math 
import random

def student_t(nu): # nu equals number of degrees of freedom
    x = random.gauss(0.0, 1.0)
    y = 2.0*random.gammavariate(0.5*nu, 2.0)
    return x / (math.sqrt(y/nu))

I found this from here https://www.johndcook.com/python_student_t_rng.html. but shouldn't the sixth line be like

y = random.gammavariate(0.5*nu, 2.0)

why is there 2.0* ?




Aucun commentaire:

Enregistrer un commentaire