random

抽奖程序

走远了吗. 提交于 2020-02-13 09:01:32
抽奖程序 'package choujiang; import java.util.ArrayList; import java.util.Collections; import java.util.Random; public class choujiang { public static void main(String[] args) { ArrayList <Integer> number = new ArrayList<>(); Random random = new Random(); for(int i=0;i<1000;i++){ int A=i; number.add(A); } Collections.shuffle(number); int A = random.nextInt(1000); System.out.println("一等奖" +number.get(A)+"\n" ); number.remove(A); for(int i=1;i<3;i++){ Collections.shuffle(number); int B = random.nextInt(1000-i); System.out.println("二等奖" +number.get(B)+"\n"); number.remove(B); } for(int i=1;i<4;i++){

Generating uniform random integers with a certain maximum

老子叫甜甜 提交于 2020-02-13 04:06:32
问题 I want to generate uniform integers that satisfy 0 <= result <= maxValue . I already have a generator that returns uniform values in the full range of the built in unsigned integer types. Let's call the methods for this byte Byte() , ushort UInt16() , uint UInt32() and ulong UInt64() . Assume that the result of these methods is perfectly uniform. The signature of the methods I want are uint UniformUInt(uint maxValue) and ulong UniformUInt(ulong maxValue) . What I'm looking for: Correctness I

猜数字游戏

空扰寡人 提交于 2020-02-13 03:01:38
public static void main(String[] args) { System.out.println("猜数字游戏开始啦!"); System.out.println("请输入1-100之间的数字"); Random ran = new Random();//创建一个随机数生成器 int ranNum = ran.nextInt(100);//生成[0,100)之间的随机数 @SuppressWarnings("resource") Scanner sc = new Scanner(System.in);//创建一个扫描器 while(true) { int inputNum = sc.nextInt();//从键盘输入获取值 if(ranNum>inputNum) { System.out.println("数字小了"); }else if(ranNum<inputNum) { System.out.println("数字大了"); }else { System.out.println("猜对了"); break; } }} 来源: https://www.cnblogs.com/a591378955/p/7841484.html

Python--模块之time、random、os、hashlib

主宰稳场 提交于 2020-02-12 15:53:18
今天开始模块。 首先补充 __init__.py 在python模块的每一个包中,都有一个__init__.py文件(这个文件定义了包的属性和方法)然后是一些模块文件和子目录,假如子目录中也有__init__.py 那么它就是这个包的子包了。当你将一个包作为模块导入(比如从 xml 导入 dom )的时候,实际上导入了它的__init__.py 文件。 一个包是一个带有特殊文件 __init__.py 的目录。__init__.py 文件定义了包的属性和方法。 其实它可以什么也不定义;可以只是一个空文件,但是必须存在。 如果 __init__.py 不存在,这个目录就仅仅是一个目录,而不是一个包,它就不能被导入或者包含其它的模块和嵌套包。 __init__.py 中还有一个重要的变量,叫做__all__。我们有时会使出一招“全部导入”。这时 import 就会把注册在包__init__.py 文件中 __all__ 列表中的子模块和子包导入到当前作用域中来。 Python查找模块的路径 运行Python应用或引用Python模块,Python解释器要有一个查找的过程。可以通过设置一个环境变量PYTHONPATH为Python增加一个搜索路径,以方便查找到相关Python模块,这与众多应用程序需要设置一个系统环境变量的道理是一样的。在命令行中可以通过以下命令设置: C:\Users

其他一些小程序

落爺英雄遲暮 提交于 2020-02-12 15:08:04
1 区间数字判断 1 import time 2 3 # 计算一定区间内内的相关操作数据 4 print('\033[1;33m================> 请输入计算区间,区间长度请勿超过3万,否则老夫的计算机...... <=====================\033[0m') 5 start = int(input('\033[1;32m请输入计算前端区间:\033[0m').strip()) 6 end = int(input('\033[1;32m请输入计算后端区间:\033[0m').strip()) 7 while True: 8 cho_dic = """ 9 '1':'质数、合数' 10 '2':'偶数、奇数' 11 '3':'完全数' 12 '4':'斐波那契数列' 13 'QUIT':'退出系统' 14 """ 15 print(cho_dic) 16 cho = input('请输入将要进行的操作代号:') 17 # 质数、合数 18 if cho == '1': 19 str_time = time.time() 20 print('正在计算中,请稍等...\n') 21 zhi_li = [] 22 for num in range(start, end): 23 for i in range(2, num): 24 if num % i =

Generate random number between 0.1 and 1.0. Python

回眸只為那壹抹淺笑 提交于 2020-02-12 08:50:50
问题 I'm trying to generate a random number between 0.1 and 1.0. We can't use rand.randint because it returns integers. We have also tried random.uniform(0.1,1.0) , but it returns a value >= 0.1 and < 1.0, we can't use this, because our search includes also 1.0. Does somebody else have an idea for this problem? 回答1: How "accurate" do you want your random numbers? If you're happy with, say, 10 decimal digits, you can just round random.uniform(0.1, 1.0) to 10 digits. That way you will include both 0

LeetCode All in One 题目讲解汇总(持续更新中...)

谁说我不能喝 提交于 2020-02-12 00:23:10
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. Example 1: Input: {"$id":"1","next":{"$id":"2","next":null,"random":{"$ref":"2"},"val":2},"random":{"$ref":"2"},"val":1} Explanation: Node 1's value is 1, both of its next and random pointer points to Node 2. Node 2's value is 2, its next pointer points to null and its random pointer points to itself. Note: You must return the copy of the given head as a reference to the cloned list. 这道链表的深度拷贝题的难点就在于如何处理随机指针的问题,由于每一个节点都有一个随机指针

python之random模块

醉酒当歌 提交于 2020-02-11 23:44:12
import random res=random.random() print(res) print(random.randint(1,4)) print(random.randrange(1,4)) print(random.choice([11,'22',33])) print(random.sample([2,3,5,8],3)) //输出结果为 [8, 5, 3] print(random.uniform(1,4)) //输出结果为 2.4596659503195655 ret=[1,2,3] random.shuffle(ret) print(ret) //输出结果为 [1, 3, 2] def r_code(): code='' for i in range(4): num=random.randint(0,9) ch=chr(random.randint(65,122)) s=str(random.choice([num,ch])) code+=s return code print(r_code()) 来源: https://www.cnblogs.com/cxydnxs/p/12297385.html

第三篇

被刻印的时光 ゝ 提交于 2020-02-11 19:34:15
import random print (random.randint( 1 , 2 ))    import random print(random.randint(-2,3))    import random a = random.randint(0,9) print(str(a)+str(a)+str(a)+str(a)+str(a)+str(a))    ame = input("请输入用户名称:") if name = "托尼史塔克": print("Welcom , 托尼") else: print("Get out , who are you!")    反了    a = 1 b = 2 if a == b: print("a和b相等") else: print("a和b不相等")    不相等    6 15    来源: https://www.cnblogs.com/w11111111111/p/12295839.html

Django【第22篇】:基于Ajax实现的登录

两盒软妹~` 提交于 2020-02-11 05:49:52
基于ajax实现的登录 一、需要知道的新知识点 1、刷新验证码。给src属性加一个?号。加个?会重新去请求 //#给验证码刷新 $(".vialdCode_img").click(function () { 方式一:dom方法#} $(this)[0].src+="?"#} 方式二:jQuery的attr方法#} $(this).attr("src",$(this).attr("src")+'?') }) }) 2、当登录成功跳转,或者注册成功跳转 $(".register").click(function () { location.href = '/register/' }); 3、超时后消失 setTimeout(foo, 3000) function foo() { $(".error").html("") } 4、auth模块的使用 模块的导入: from django.contrib import auth 几个使用方法: 1 、authenticate() :验证用户输入的用户名和密码是否相同 提供了用户认证,即验证用户名以及密码是否正确,一般需要username password两个关键字参数 user = authenticate(username='someone',password='somepassword') 2 、login(HttpRequest,