Python中 random.randint方法的具體用法?Python 中random.randint怎么用?Python 中random.randint使用的例子?以下例子或許可以幫助到你:
示例1: __init__
# 需要導入模塊: import random [as 別名] # 或者: from random import randint [as 別名] def __init__(self, name, infected, infection_length, initiative, coupling_tendency, condom_use, test_frequency, commitment, coupled=False, coupled_length=0, known=False, partner=None): init_state = random.randint(0, 3) super().__init__(name, "wandering around", NSTATES, init_state) self.coupled = coupled self.couple_length = coupled_length self.partner = partner self.initiative = initiative self.infected = infected self.known = known self.infection_length = infection_length self.coupling_tendency = coupling_tendency self.condom_use = condom_use self.test_frequency = test_frequency self.commitment = commitment self.state = init_state self.update_ntype()
示例2: test_get_my_pop
# 需要導入模塊: import random [as 別名] # 或者: from random import randint [as 別名] def test_get_my_pop(self): report = True for var in self.dic_for_reference: for a in self.dic_for_reference[var][AGENTS]: self.agentpop.append(a) var = str(random.randint(0, 2)) dummy_node = node.Node("dummy node") dummy_node.ntype = var self.agentpop.append(dummy_node) self.dic_for_reference[var][AGENTS].append(dummy_node) result = self.agentpop.get_my_pop(dummy_node) correct_pop = len(self.dic_for_reference[var][AGENTS]) if result != correct_pop: report = False self.assertEqual(report, True)
以上為PYTHON的方法,如果想了解web前端內容,包括html,css,Javascript可以點擊相關鏈接