當前位置: 首頁>>代碼示例>>Python>>正文


Python random.expovariate方法代碼示例

本文整理匯總了Python中random.expovariate方法的典型用法代碼示例。如果您正苦於以下問題:Python random.expovariate方法的具體用法?Python random.expovariate怎麽用?Python random.expovariate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在random的用法示例。


在下文中一共展示了random.expovariate方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: poisson_source

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def poisson_source(rate, iterable, target):
    """Send events at random times with uniform probability.

    Args:
        rate: The average number of events to send per second.
        iterable: A series of items which will be sent to the target one by one.
        target: The target coroutine or sink.

    Returns:
        An iterator over any remaining items.
    """
    if rate <= 0.0:
        raise ValueError("poisson_source rate {} is not positive".format(rate))

    it = iter(iterable)
    for item in it:
        duration = random.expovariate(rate)
        sleep(duration)
        try:
            target.send(item)
        except StopIteration:
            return prepend(item, it)
    return empty_iter() 
開發者ID:sixty-north,項目名稱:python-transducers,代碼行數:25,代碼來源:sources.py

示例2: test_explicit_from_float

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def test_explicit_from_float(self):
        r = Decimal(0.1)
        self.assertEqual(type(r), Decimal)
        self.assertEqual(str(r),
                '0.1000000000000000055511151231257827021181583404541015625')
        self.assertTrue(Decimal(float('nan')).is_qnan())
        self.assertTrue(Decimal(float('inf')).is_infinite())
        self.assertTrue(Decimal(float('-inf')).is_infinite())
        self.assertEqual(str(Decimal(float('nan'))),
                         str(Decimal('NaN')))
        self.assertEqual(str(Decimal(float('inf'))),
                         str(Decimal('Infinity')))
        self.assertEqual(str(Decimal(float('-inf'))),
                         str(Decimal('-Infinity')))
        self.assertEqual(str(Decimal(float('-0.0'))),
                         str(Decimal('-0')))
        for i in range(200):
            x = random.expovariate(0.01) * (random.random() * 2.0 - 1.0)
            self.assertEqual(x, float(Decimal(x))) # roundtrip 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_decimal.py

示例3: test_from_float

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def test_from_float(self):

        class  MyDecimal(Decimal):
            pass

        r = MyDecimal.from_float(0.1)
        self.assertEqual(type(r), MyDecimal)
        self.assertEqual(str(r),
                '0.1000000000000000055511151231257827021181583404541015625')
        bigint = 12345678901234567890123456789
        self.assertEqual(MyDecimal.from_float(bigint), MyDecimal(bigint))
        self.assertTrue(MyDecimal.from_float(float('nan')).is_qnan())
        self.assertTrue(MyDecimal.from_float(float('inf')).is_infinite())
        self.assertTrue(MyDecimal.from_float(float('-inf')).is_infinite())
        self.assertEqual(str(MyDecimal.from_float(float('nan'))),
                         str(Decimal('NaN')))
        self.assertEqual(str(MyDecimal.from_float(float('inf'))),
                         str(Decimal('Infinity')))
        self.assertEqual(str(MyDecimal.from_float(float('-inf'))),
                         str(Decimal('-Infinity')))
        self.assertRaises(TypeError, MyDecimal.from_float, 'abc')
        for i in range(200):
            x = random.expovariate(0.01) * (random.random() * 2.0 - 1.0)
            self.assertEqual(x, float(MyDecimal.from_float(x))) # roundtrip 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_decimal.py

示例4: _fix

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0,1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05)+1)
            return o("".join([random.choice(self.chars) for i in range(z)]))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08)+1)
            return o(map(lambda x:x._fix(n+1), [self.__class__(objlist=self.objlist)]*z))
        return ASN1_INTEGER(int(random.gauss(0,1000)))


##############
#### ASN1 ####
############## 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:21,代碼來源:asn1.py

示例5: random_tree_demo

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def random_tree_demo(num_leaf_pops, lins_per_pop):
    #events_list = []
    sampled_pops = list(range(1, num_leaf_pops + 1))
    model = momi.DemographicModel(1.0, .25)
    for p in sampled_pops:
        model.add_leaf(p, N=random.expovariate(1.0))
    roots = list(sampled_pops)
    #for i in roots:
    #    events_list += [('-en', 0.0, i, random.expovariate(1.0))]
    t = 0.0
    while len(roots) > 1:
        i, j = random.sample(roots, 2)
        t += random.expovariate(1.0)
        #events_list += [('-ej', t, i, j),
        #                ('-en', t, j, random.expovariate(1.0))]
        model.move_lineages(i, j, t, N=random.expovariate(1.0))
        roots.remove(i)
    #return make_demo_hist(events_list, sampled_pops, [lins_per_pop] * num_leaf_pops)
    return model
    # return make_demography(events_list, sampled_pops, [lins_per_pop] *
    # num_leaf_pops) 
開發者ID:popgenmethods,項目名稱:momi2,代碼行數:23,代碼來源:demo_utils.py

示例6: test_pick_providers

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def test_pick_providers(self, mock1):

        self.vps = cloudomate.get_vps_providers
        self.get_gateway = blueAngel.BlueAngelHost.get_gateway
        self.estimate_price = Coinbase.Coinbase.estimate_price
        self.get_price = wallet_util.get_price
        self.get_fee = wallet_util.get_network_fee

        # cloudomate.get_vps_providers = MagicMock(
        #     return_value=CaseInsensitiveDict({'blueangelhost': blueAngel.BlueAngelHost}))
        random.expovariate = MagicMock(return_value=0.55)
        blueAngel.BlueAngelHost.get_gateway = MagicMock()
        Coinbase.Coinbase.estimate_price = MagicMock()
        cloudomate.pick_option = MagicMock(return_value=[1, 2, 3])
        wallet_util.get_price = MagicMock()
        wallet_util.get_network_fee = MagicMock()

        cloudomate.pick_provider(cloudomate.get_vps_providers())
        blueAngel.BlueAngelHost.get_gateway.assert_called_once()

        cloudomate.get_vps_providers = self.vps
        blueAngel.BlueAngelHost.get_gateway = self.get_gateway
        Coinbase.Coinbase.estimate_price = self.estimate_price
        wallet_util.get_price = self.get_price
        wallet_util.get_network_fee = self.get_fee 
開發者ID:Tribler,項目名稱:Dollynator,代碼行數:27,代碼來源:test_cloudomate_controller.py

示例7: _fix

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0, 1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_GENERALIZED_TIME) or issubclass(o, ASN1_UTC_TIME):  # noqa: E501
            z = GeneralizedTime()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05) + 1)
            return o("".join(random.choice(self.chars) for _ in range(z)))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08) + 1)
            return o([self.__class__(objlist=self.objlist)._fix(n + 1)
                      for _ in range(z)])
        return ASN1_INTEGER(int(random.gauss(0, 1000)))


##############
#    ASN1    #
############## 
開發者ID:secdev,項目名稱:scapy,代碼行數:25,代碼來源:asn1.py

示例8: test_explicit_from_float

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def test_explicit_from_float(self):

        Decimal = self.decimal.Decimal

        r = Decimal(0.1)
        self.assertEqual(type(r), Decimal)
        self.assertEqual(str(r),
                '0.1000000000000000055511151231257827021181583404541015625')
        self.assertTrue(Decimal(float('nan')).is_qnan())
        self.assertTrue(Decimal(float('inf')).is_infinite())
        self.assertTrue(Decimal(float('-inf')).is_infinite())
        self.assertEqual(str(Decimal(float('nan'))),
                         str(Decimal('NaN')))
        self.assertEqual(str(Decimal(float('inf'))),
                         str(Decimal('Infinity')))
        self.assertEqual(str(Decimal(float('-inf'))),
                         str(Decimal('-Infinity')))
        self.assertEqual(str(Decimal(float('-0.0'))),
                         str(Decimal('-0')))
        for i in range(200):
            x = random.expovariate(0.01) * (random.random() * 2.0 - 1.0)
            self.assertEqual(x, float(Decimal(x))) # roundtrip 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:24,代碼來源:test_decimal.py

示例9: test_explicit_context_create_from_float

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def test_explicit_context_create_from_float(self):

        Decimal = self.decimal.Decimal

        nc = self.decimal.Context()
        r = nc.create_decimal(0.1)
        self.assertEqual(type(r), Decimal)
        self.assertEqual(str(r), '0.1000000000000000055511151231')
        self.assertTrue(nc.create_decimal(float('nan')).is_qnan())
        self.assertTrue(nc.create_decimal(float('inf')).is_infinite())
        self.assertTrue(nc.create_decimal(float('-inf')).is_infinite())
        self.assertEqual(str(nc.create_decimal(float('nan'))),
                         str(nc.create_decimal('NaN')))
        self.assertEqual(str(nc.create_decimal(float('inf'))),
                         str(nc.create_decimal('Infinity')))
        self.assertEqual(str(nc.create_decimal(float('-inf'))),
                         str(nc.create_decimal('-Infinity')))
        self.assertEqual(str(nc.create_decimal(float('-0.0'))),
                         str(nc.create_decimal('-0')))
        nc.prec = 100
        for i in range(200):
            x = random.expovariate(0.01) * (random.random() * 2.0 - 1.0)
            self.assertEqual(x, float(nc.create_decimal(x))) # roundtrip 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:25,代碼來源:test_decimal.py

示例10: __init__

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def __init__(self, index_name, type_name, conflicting_ids=None, conflict_probability=None, on_conflict=None,
                 recency=None, rand=random.random, randint=random.randint, randexp=random.expovariate):
        if type_name:
            self.meta_data_index_with_id = '{"index": {"_index": "%s", "_type": "%s", "_id": "%s"}}\n' % \
                                           (index_name, type_name, "%s")
            self.meta_data_update_with_id = '{"update": {"_index": "%s", "_type": "%s", "_id": "%s"}}\n' % \
                                            (index_name, type_name, "%s")
            self.meta_data_index_no_id = '{"index": {"_index": "%s", "_type": "%s"}}\n' % (index_name, type_name)
        else:
            self.meta_data_index_with_id = '{"index": {"_index": "%s", "_id": "%s"}}\n' % (index_name, "%s")
            self.meta_data_update_with_id = '{"update": {"_index": "%s", "_id": "%s"}}\n' % (index_name, "%s")
            self.meta_data_index_no_id = '{"index": {"_index": "%s"}}\n' % index_name

        self.conflicting_ids = conflicting_ids
        self.on_conflict = on_conflict
        # random() produces numbers between 0 and 1 and the user denotes the probability in percentage between 0 and 100
        self.conflict_probability = conflict_probability / 100.0 if conflict_probability is not None else 0
        self.recency = recency if recency is not None else 0

        self.rand = rand
        self.randint = randint
        self.randexp = randexp
        self.id_up_to = 0 
開發者ID:elastic,項目名稱:rally,代碼行數:25,代碼來源:params.py

示例11: _think

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def _think(self):
        try:
            if len(self.conns) < self.desired_conns and len(self.attempts) < self.max_attempts and self.node.addr_store:
                (host, port), = self.node.get_good_peers(1)
                
                if self._host_to_ident(host) in self.attempts:
                    pass
                elif host in self.node.bans and self.node.bans[host] > time.time():
                    pass
                else:
                    #print 'Trying to connect to', host, port
                    reactor.connectTCP(host, port, self, timeout=5)
        except:
            log.err()
        
        return random.expovariate(1/1) 
開發者ID:donSchoe,項目名稱:p2pool-n,代碼行數:18,代碼來源:p2p.py

示例12: get_common_ancestor_waiting_time

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def get_common_ancestor_waiting_time(self, t):
        """
        Returns the random waiting time until a common ancestor event
        occurs within this population.
        """
        ret = sys.float_info.max
        k = self.get_num_ancestors()
        if k > 1:
            u = random.expovariate(k * (k - 1))
            if self.growth_rate == 0:
                ret = self.start_size * u
            else:
                dt = t - self.start_time
                z = (
                    1
                    + self.growth_rate
                    * self.start_size
                    * math.exp(-self.growth_rate * dt)
                    * u
                )
                if z > 0:
                    ret = math.log(z) / self.growth_rate
        return ret 
開發者ID:tskit-dev,項目名稱:msprime,代碼行數:25,代碼來源:algorithms.py

示例13: _fix

# 需要導入模塊: import random [as 別名]
# 或者: from random import expovariate [as 別名]
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0,1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05)+1)
            return o(bytes([random.choice(self.chars) for i in range(z)]))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08)+1)
#            return o(map(lambda x:x._fix(n+1), [self.__class__(objlist=self.objlist)]*z))
            return o([ x._fix(n+1) for x in [self.__class__(objlist=self.objlist)]*z])
        return ASN1_INTEGER(int(random.gauss(0,1000)))


##############
#### ASN1 ####
############## 
開發者ID:phaethon,項目名稱:kamene,代碼行數:22,代碼來源:asn1.py


注:本文中的random.expovariate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。