random

Generating a list of random permutations of another list

孤人 提交于 2020-02-07 18:39:32
问题 So, I'm trying to tackle the TSP with a Genetic Algorithm. To do that I need to create a population pool. What I wan't to accomplish is to create a list of random permutations that will represent a population pool. I'm trying to do this using random.shuffle. Here's my code that should handle that part. Cities is a list of cities and routes is where I want to keep the population pool (a list of N random permutations): for x in range(n): random.shuffle(cities) routes.append(cities) What happens

Generating a list of random permutations of another list

微笑、不失礼 提交于 2020-02-07 18:39:13
问题 So, I'm trying to tackle the TSP with a Genetic Algorithm. To do that I need to create a population pool. What I wan't to accomplish is to create a list of random permutations that will represent a population pool. I'm trying to do this using random.shuffle. Here's my code that should handle that part. Cities is a list of cities and routes is where I want to keep the population pool (a list of N random permutations): for x in range(n): random.shuffle(cities) routes.append(cities) What happens

软件工程结对作业(四则运算web版)01

无人久伴 提交于 2020-02-07 07:13:30
转自:http://www.cnblogs.com/fylove/p/6676453.html 结对人:胡建峰、高雪彤 设计思想 在以前的程序基础上两人结合开发web系统。 首先编写了一个登录界面,实现的是不同用户,不同题库的功能。 然后进入主页,主页中在登录成功后显示用户名,并有开始答题,查看历史错题和注销三个按钮。开始答题按钮可以供用户选择出题的条件生成题目,查看历史错题会调出数据库中历史的错题,也可以重新做这些错题,注销会注销当前用户,返回登录界面。 出题界面会显示用户的条件,在下面生成题目,后面有一个输入框,供用户答题,不会的可以空下,最后点击提交可以进入结果验证页面,结果页面中,会对输入和信息与数据库中的作对比,正确的显示一个正确的图片,错误会显示一个错误的图片并显示正确答案,并将错误答案和信息存入数据库。 重做错题,从数据库中导出错题和错误答案,在修改提交后,会进行判断。 在最后对页面使用了Javabean、servlet、ajax、jQuery,并对页面进行了美化。 源程序代码 1 package bean; 2 3 import java.sql.*; 4 import com.db.DB; 5 6 public class User { 7 private String username; 8 private String userpass; 9 10

Cannot understand why random number algorithms give different results

寵の児 提交于 2020-02-07 05:44:06
问题 I'm trying to understand why the following 2 code snippets lead to different output and I'm hoping someone can enlighten me. The second version is marginally faster - which is my motivation since this all sits in a loop, but I need to know if it is equivalent and if not then why ? things <- 100000 n.events <- 3 probs <- rep(0.05, n.events) # Method 1 set.seed(1) events1 <- matrix(n.events, nrow=things) events1 <- sapply(probs, function(probs) rbinom(things,1,probs)) # Method 2 set.seed(1)

Visualizing Random Walk In Python Using Matplotlib

大城市里の小女人 提交于 2020-02-07 04:25:33
Original place: https://don.easiestsoft.com/random-walk/ Random Walk A random walk is the process by which randomly-moving objects wander away from where they started. There are many kinds of Random Walk, but we only consider Lattice Random Walk Problem in this article, which simply assumes the object is walking on a lattice. Matplotlib Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. (from Matplotlib Documentation) Simply put, it is one of python’s mathematical drawing

java day07【Scanner类、Random类、ArrayList 类】

倾然丶 夕夏残阳落幕 提交于 2020-02-06 16:39:21
第1章 API 概述   API(Application Programming Interface),应用程序编程接口。Java API是一本程序员的 字典 ,是JDK中提供给 我们使用的类的说明文档。这些类将底层的代码实现封装了起来,我们不需要关心这些类是如何实现的,只需要学 习这些类如何使用即可。所以我们可以通过查询API的方式,来学习Java提供的类,并得知如何使用它们。 API使用步骤 1. 打开帮助文档。 2. 点击显示,找到索引,看到输入框。 3. 你要找谁?在输入框里输入,然后回车。 4. 看包。java.lang下的类不需要导包,其他需要。 5. 看类的解释和说明。 6. 学习构造方法。 7. 使用成员方法。 第2章 Scanner类   了解了API的使用方式,我们通过Scanner类,熟悉一下查询API,并使用类的步骤。 2.1 什么是Scanner类   一个可以解析基本类型和字符串的简单文本扫描器。 例如,以下代码使用户能够从 System.in 中读取一个数:   Scanner sc = new Scanner(System.in);    int i = sc.nextInt(); 备注:System.in 系统输入指的是通过键盘录入数据。 2.2 引用类型使用步骤 导包   使用import关键字导包,在类的所有代码之前导包,引入要使用的类型

How to generate unique random numbers (that don't repeat)?

喜欢而已 提交于 2020-02-06 06:48:16
问题 I'm trying to write a code that randomly chooses numbers and adds them to the list random_numbers , but if a random number was already generated, the code detects that and replaces the number with another, until every number is different. import random random_numbers = [] for x in range(11): This part generates a random integer and appends it to the list random_numbers : random_numbers.append('[q' + str(random.randint(1, 11)) + ']') This part is supposed to iterate over the list and check if

How to generate unique random numbers (that don't repeat)?

久未见 提交于 2020-02-06 06:45:34
问题 I'm trying to write a code that randomly chooses numbers and adds them to the list random_numbers , but if a random number was already generated, the code detects that and replaces the number with another, until every number is different. import random random_numbers = [] for x in range(11): This part generates a random integer and appends it to the list random_numbers : random_numbers.append('[q' + str(random.randint(1, 11)) + ']') This part is supposed to iterate over the list and check if

How does Polkadot's VRF achieve randomness to shuffle validators?

只谈情不闲聊 提交于 2020-02-06 06:38:45
问题 Contrary to Ethereum which uses RANDAO (possibly enhanced with VDF), in Polkadot, a verifiable random function (VRF) is used to shuffle validators and select potential block proposers for certain slots. Where does the randomness come from, i.e. how does the randomness work specifically? 回答1: A verifiable random function is a function that, in pseudocode, can be expressed like so: (RESULT, PROOF) = VRF(SECRET, INPUT) That is, for some secret and some input (which can be public), the result is

How to generate random numbers at set time intervals?

为君一笑 提交于 2020-02-06 05:13:06
问题 I have developed code in Java for generating ten random numbers from a range 0 to 99. The problem is I need to generate a random number for every 2 min. I am new to this area and need your views. 回答1: This example adds a random number to a blocking dequeue every two minutes. You can take the numbers from the queue when you need them. You can use java.util.Timer as a lightweight facility to schedule the number generation or you can use java.util.concurrent.ScheduledExecutorService for a more