Python random.gammavariate() Examples

The following are 22 code examples of random.gammavariate(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module random , or try the search function .
Example #1
Source File: __main__.py    From slicesim with MIT License 6 votes vote down vote up
def get_dist(d):
    return {
        'randrange': random.randrange, # start, stop, step
        'randint': random.randint, # a, b
        'random': random.random,
        'uniform': random, # a, b
        'triangular': random.triangular, # low, high, mode
        'beta': random.betavariate, # alpha, beta
        'expo': random.expovariate, # lambda
        'gamma': random.gammavariate, # alpha, beta
        'gauss': random.gauss, # mu, sigma
        'lognorm': random.lognormvariate, # mu, sigma
        'normal': random.normalvariate, # mu, sigma
        'vonmises': random.vonmisesvariate, # mu, kappa
        'pareto': random.paretovariate, # alpha
        'weibull': random.weibullvariate # alpha, beta
    }.get(d) 
Example #2
Source File: test_random.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def test_zeroinputs(self):
        # Verify that distributions can handle a series of zero inputs'
        g = random.Random()
        x = [g.random() for i in range(50)] + [0.0]*5
        g.random = x[:].pop; g.uniform(1,10)
        g.random = x[:].pop; g.paretovariate(1.0)
        g.random = x[:].pop; g.expovariate(1.0)
        g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
        g.random = x[:].pop; g.normalvariate(0.0, 1.0)
        g.random = x[:].pop; g.gauss(0.0, 1.0)
        g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
        g.random = x[:].pop; g.gammavariate(0.01, 1.0)
        g.random = x[:].pop; g.gammavariate(1.0, 1.0)
        g.random = x[:].pop; g.gammavariate(200.0, 1.0)
        g.random = x[:].pop; g.betavariate(3.0, 3.0)
        g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0) 
Example #3
Source File: test_endpoint_responses_valid.py    From nba_api with MIT License 6 votes vote down vote up
def test_endpoints_run(deferred_endpoint):
    '''Test that each endpoint is callable.
    
    This takes a very, very long time in total (10-20 minutes) because we don't
    want to barrage the NBA site with requests.'''
    # Delay briefly
    wait = random.gammavariate(alpha=9, beta=0.4)
    time.sleep(wait)
    # Call the API.
    try:
        response = deferred_endpoint()
    except json.decoder.JSONDecodeError:
        endpoint_class = deferred_endpoint.endpoint_class
        msg = 'Unable to decode response for {}'.format(endpoint_class)
        pytest.fail(msg=msg)
    # We want to hang onto all the responses so we don't need to re-retrieve
    # them later.
    cached_eps.append(response) 
Example #4
Source File: test_random.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def test_zeroinputs(self):
        # Verify that distributions can handle a series of zero inputs'
        g = random.Random()
        x = [g.random() for i in range(50)] + [0.0]*5
        g.random = x[:].pop; g.uniform(1,10)
        g.random = x[:].pop; g.paretovariate(1.0)
        g.random = x[:].pop; g.expovariate(1.0)
        g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
        g.random = x[:].pop; g.normalvariate(0.0, 1.0)
        g.random = x[:].pop; g.gauss(0.0, 1.0)
        g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
        g.random = x[:].pop; g.gammavariate(0.01, 1.0)
        g.random = x[:].pop; g.gammavariate(1.0, 1.0)
        g.random = x[:].pop; g.gammavariate(200.0, 1.0)
        g.random = x[:].pop; g.betavariate(3.0, 3.0)
        g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0) 
Example #5
Source File: test_random.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def test_zeroinputs(self):
        # Verify that distributions can handle a series of zero inputs'
        g = random.Random()
        x = [g.random() for i in range(50)] + [0.0]*5
        g.random = x[:].pop; g.uniform(1,10)
        g.random = x[:].pop; g.paretovariate(1.0)
        g.random = x[:].pop; g.expovariate(1.0)
        g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
        g.random = x[:].pop; g.normalvariate(0.0, 1.0)
        g.random = x[:].pop; g.gauss(0.0, 1.0)
        g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
        g.random = x[:].pop; g.gammavariate(0.01, 1.0)
        g.random = x[:].pop; g.gammavariate(1.0, 1.0)
        g.random = x[:].pop; g.gammavariate(200.0, 1.0)
        g.random = x[:].pop; g.betavariate(3.0, 3.0)
        g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0) 
Example #6
Source File: volatile.py    From dash-hack with MIT License 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #7
Source File: volatile.py    From arissploit with GNU General Public License v3.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #8
Source File: volatile.py    From kamene with GNU General Public License v2.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #9
Source File: simulator.py    From research with MIT License 5 votes vote down vote up
def poisson_latency(latency):
    return lambda: 1 + int(random.gammavariate(1, 1) * latency) 
Example #10
Source File: volatile.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #11
Source File: test_random.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_gammavariate_errors(self):
        # Both alpha and beta must be > 0.0
        self.assertRaises(ValueError, random.gammavariate, -1, 3)
        self.assertRaises(ValueError, random.gammavariate, 0, 2)
        self.assertRaises(ValueError, random.gammavariate, 2, 0)
        self.assertRaises(ValueError, random.gammavariate, 1, -3) 
Example #12
Source File: volatile.py    From isip with MIT License 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #13
Source File: stats.py    From filterpy with MIT License 5 votes vote down vote up
def rand_student_t(df, mu=0, std=1):
    """
    return random number distributed by student's t distribution with
    `df` degrees of freedom with the specified mean and standard deviation.
    """

    x = random.gauss(0, std)
    y = 2.0*random.gammavariate(0.5 * df, 2.0)
    return x / (math.sqrt(y / df)) + mu 
Example #14
Source File: volatile.py    From CyberScan with GNU General Public License v3.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #15
Source File: volatile.py    From dash-hack with MIT License 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #16
Source File: volatile.py    From dash-hack with MIT License 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #17
Source File: test_random.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_gammavariate_errors(self):
        # Both alpha and beta must be > 0.0
        self.assertRaises(ValueError, random.gammavariate, -1, 3)
        self.assertRaises(ValueError, random.gammavariate, 0, 2)
        self.assertRaises(ValueError, random.gammavariate, 2, 0)
        self.assertRaises(ValueError, random.gammavariate, 1, -3) 
Example #18
Source File: test_random.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_gammavariate_errors(self):
        # Both alpha and beta must be > 0.0
        self.assertRaises(ValueError, random.gammavariate, -1, 3)
        self.assertRaises(ValueError, random.gammavariate, 0, 2)
        self.assertRaises(ValueError, random.gammavariate, 2, 0)
        self.assertRaises(ValueError, random.gammavariate, 1, -3) 
Example #19
Source File: volatile.py    From scapy with GNU General Public License v2.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #20
Source File: volatile.py    From mptcp-abuse with GNU General Public License v2.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #21
Source File: volatile.py    From CVE-2016-6366 with MIT License 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example #22
Source File: volatile.py    From smod-1 with GNU General Public License v2.0 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))