当前位置: 首页>>代码示例>>Python>>正文


Python random.randint方法代码示例

本文整理汇总了Python中random.randint方法的典型用法代码示例。如果您正苦于以下问题:Python random.randint方法的具体用法?Python random.randint怎么用?Python random.randint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在random的用法示例。


在下文中一共展示了random.randint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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) 
开发者ID:gcallah,项目名称:indras_net,代码行数:18,代码来源:test_agent_pop.py

示例2: __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() 
开发者ID:gcallah,项目名称:indras_net,代码行数:20,代码来源:hiv.py

示例3: test_get_pop_data

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def test_get_pop_data(self):
        report = True
        check_list = []
        for var in self.dic_for_reference:
            random_pop_data = random.randint(1,10)
            check_list.append(random_pop_data)
            for a in self.dic_for_reference[var][AGENTS]:
                self.agentpop.append(a)
            self.agentpop.vars[var][POP_DATA] = random_pop_data
        index = 0
        for var in self.agentpop.vars:
            result = self.agentpop.get_pop_data(var)
            if result != check_list[index]:
                report = False
                break
            index += 1

        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:20,代码来源:test_agent_pop.py

示例4: __init__

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def __init__(self, methodName, prop_file="models/basic_for_test.props"):
    
        super().__init__(methodName=methodName)
    
        pa = props.read_props(MODEL_NM, prop_file)
        # if result:
        #     pa.overwrite_props_from_dict(result.props)
        # else:
        #     print("Oh-oh, no props to read in!")
        #     exit(1)
    
        # Now we create a minimal environment for our agents to act within:
        self.env = bm.BasicEnv(model_nm=MODEL_NM, props=pa)
    
        # Now we loop creating multiple agents
        #  with numbered names based on the loop variable:
        for i in range(pa.props.get("num_agents").val):
            self.env.add_agent(bm.BasicAgent(name="agent" + str(i),
                                        goal="acting up!"))
        self.env.add_agent(bm.BasicAgent(name="agent for tracking",
                                         goal="acting up!"))

        # self.env.n_steps(random.randint(10, 20)) 
开发者ID:gcallah,项目名称:indras_net,代码行数:25,代码来源:test_basic.py

示例5: anneal

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def anneal(self):
        """
        Execute simulated annealing algorithm.
        """
        # Initialize with the greedy solution.
        self.cur_solution, self.cur_fitness = self.initial_solution()

        print("Starting annealing.")
        while self.T >= self.stopping_temperature and self.iteration < self.stopping_iter:
            candidate = list(self.cur_solution)
            l = random.randint(2, self.N - 1)
            i = random.randint(0, self.N - l)
            candidate[i : (i + l)] = reversed(candidate[i : (i + l)])
            self.accept(candidate)
            self.T *= self.alpha
            self.iteration += 1

            self.fitness_list.append(self.cur_fitness)

        print("Best fitness obtained: ", self.best_fitness)
        improvement = 100 * (self.fitness_list[0] - self.best_fitness) / (self.fitness_list[0])
        print(f"Improvement over greedy heuristic: {improvement : .2f}%") 
开发者ID:chncyhn,项目名称:simulated-annealing-tsp,代码行数:24,代码来源:anneal.py

示例6: _capture2dImage

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def _capture2dImage(self, cameraId):
        # Capture Image in RGB

        # WARNING : The same Name could be used only six time.
        strName = "capture2DImage_{}".format(random.randint(1,10000000000))

        clientRGB = self.video_service.subscribeCamera(strName, cameraId, AL_kVGA, 11, 10)
        imageRGB = self.video_service.getImageRemote(clientRGB)

        imageWidth   = imageRGB[0]
        imageHeight  = imageRGB[1]
        array        = imageRGB[6]
        image_string = str(bytearray(array))

        # Create a PIL Image from our pixel array.
        im = Image.frombytes("RGB", (imageWidth, imageHeight), image_string)

        # Save the image.
        image_name_2d = "images/img2d-" + str(self.imageNo2d) + ".png"
        im.save(image_name_2d, "PNG") # Stored in images folder in the pwd, if not present then create one
        self.imageNo2d += 1
        im.show()

        return 
开发者ID:maverickjoy,项目名称:pepper-robot-programming,代码行数:26,代码来源:asthama_search.py

示例7: _capture3dImage

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def _capture3dImage(self):
        # Depth Image in RGB

        # WARNING : The same Name could be used only six time.
        strName = "capture3dImage_{}".format(random.randint(1,10000000000))


        clientRGB = self.video_service.subscribeCamera(strName, AL_kDepthCamera, AL_kQVGA, 11, 10)
        imageRGB = self.video_service.getImageRemote(clientRGB)

        imageWidth  = imageRGB[0]
        imageHeight = imageRGB[1]
        array       = imageRGB[6]
        image_string = str(bytearray(array))

        # Create a PIL Image from our pixel array.
        im = Image.frombytes("RGB", (imageWidth, imageHeight), image_string)
        # Save the image.
        image_name_3d = "images/img3d-" + str(self.imageNo3d) + ".png"
        im.save(image_name_3d, "PNG") # Stored in images folder in the pwd, if not present then create one
        self.imageNo3d += 1
        im.show()

        return 
开发者ID:maverickjoy,项目名称:pepper-robot-programming,代码行数:26,代码来源:asthama_search.py

示例8: _capture2dImage

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def _capture2dImage(self, cameraId):
        # Capture Image in RGB

        # WARNING : The same Name could be used only six time.
        strName = "capture2DImage_{}".format(random.randint(1,10000000000))


        clientRGB = self.video.subscribeCamera(strName, cameraId, AL_kVGA, 11, 10)
        imageRGB = self.video.getImageRemote(clientRGB)

        imageWidth = imageRGB[0]
        imageHeight = imageRGB[1]
        array = imageRGB[6]
        image_string = str(bytearray(array))

        # Create a PIL Image from our pixel array.
        im = Image.frombytes("RGB", (imageWidth, imageHeight), image_string)

        # Save the image inside the images foler in pwd.
        image_name_2d = "images/img2d-" + str(self.imageNo2d) + ".png"
        im.save(image_name_2d, "PNG") # Stored in images folder in the pwd, if not present then create one
        self.imageNo2d += 1
        im.show()

        return 
开发者ID:maverickjoy,项目名称:pepper-robot-programming,代码行数:27,代码来源:remote_voice.py

示例9: _capture3dImage

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def _capture3dImage(self):
        # Depth Image in RGB

        # WARNING : The same Name could be used only six time.
        strName = "capture3dImage_{}".format(random.randint(1,10000000000))

        clientRGB = self.video.subscribeCamera(strName, AL_kDepthCamera, AL_kQVGA, 11, 15)
        imageRGB = self.video.getImageRemote(clientRGB)

        imageWidth = imageRGB[0]
        imageHeight = imageRGB[1]
        array = imageRGB[6]
        image_string = str(bytearray(array))

        # Create a PIL Image from our pixel array.
        im = Image.frombytes("RGB", (imageWidth, imageHeight), image_string)

        # Save the image inside the images foler in pwd.
        image_name_3d = "images/img3d-" + str(self.imageNo3d) + ".png"
        im.save(image_name_3d, "PNG") # Stored in images folder in the pwd, if not present then create one
        self.imageNo3d += 1
        im.show()

        return 
开发者ID:maverickjoy,项目名称:pepper-robot-programming,代码行数:26,代码来源:remote_voice.py

示例10: random_optimize

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def random_optimize(GA, GB, n_iter=20):
    best_c = None
    best_order = None
    best_depth = None
    best_quality = -1
    for it in range(n_iter):
        c = random.randint(1, 7)
        order = random.randint(1, 10)
        depth = random.randint(1, 20)
        pairings = match(GA, GB, complexity=c, order=order, max_depth=depth)
        quality = compute_quality(GA, GB, pairings)
        if quality > best_quality:
            best_quality = quality
            best_c = c
            best_order = order
            best_depth = depth
    logging.debug('[random search] quality:%.2f c:%d o:%d d:%d' % (best_quality, best_c, best_order, best_depth))
    return best_quality, best_c, best_order, best_depth 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:20,代码来源:__init__.py

示例11: reset

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def reset(self):
        c_x, c_y = self.canvas.get_shape()
        c_y -= 3

        self.position = (random.randint(0, c_x - 1), random.randint(0, c_y - 1))

        self.score = random.randint(0, len(self.colours) - 1)

        self.eaten = False 
开发者ID:pimoroni,项目名称:unicorn-hat-hd,代码行数:11,代码来源:snake.py

示例12: generateChallenge

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def generateChallenge(cls):
        #  Random challenge is 8 to 64 bytes.
        #  Texas Instruments accepts only 16 byte long challenge.
        #  For this reason challenge size is 16 bytes at the moment.
        len_ = 16
        result = [None] * len_
        pos = 0
        while pos != len_:
            result[pos] = random.randint(0, 255)
            pos += 1
        return result 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:13,代码来源:GXSecure.py

示例13: rand_x

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def rand_x(self, low=0, high=None):
        """
        Return a random x-value between 0 and this space's width,
        if no constraints are passed.
        With constraints, narrow to that range.
        """
        high = self.width if high is None else high
        return randint(low, high) 
开发者ID:gcallah,项目名称:indras_net,代码行数:10,代码来源:space.py

示例14: rand_y

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def rand_y(self, low=0, high=None):
        """
        Return a random y-value between 0 and this space's height
        if no constraints are passed.
        With constraints, narrow to that range.
        """
        high = self.height if high is None else high
        return randint(low, high) 
开发者ID:gcallah,项目名称:indras_net,代码行数:10,代码来源:space.py

示例15: get_rand_vector_mag

# 需要导入模块: import random [as 别名]
# 或者: from random import randint [as 别名]
def get_rand_vector_mag(dist):
    vector_mag = random.randint(1, dist)
    return vector_mag 
开发者ID:gcallah,项目名称:indras_net,代码行数:5,代码来源:obst.py


注:本文中的random.randint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。