import random
from random import random, uniform, randint, randrange, choice, sample, shuffle list = ['jack', 'rose', 'tom', 'jerry']
print(random()) # 随机小数 0.0 <= x < 1.0
print(uniform(1, 10)) # 随机小数 x, 1.0 <= x < 10.0
print(randint(1, 10)) # 随机整数 1 to 10, endpoints included
print(randrange(0, 101, 2)) # 随机0-101,步进2,也就是偶数
print(randrange(0, 101, 5)) # 随机0-101,步进5,也就是5的倍数
print(choice('abcdefghij')) # 随机字符串中的一个字符
items = [1, 2, 3, 4, 5, 6, 7]
print(items)
shuffle(items) # 重新随机排序
print(items)
print(sample([1, 2, 3, 4, 5], 3)) # 随机选3个

  

python随机数,随机选择……random的更多相关文章

  1. Python之随机选择 random

    随机选择:random import random # 从一个序列中随机的抽取一个元素 values=[1,2,3,4,56] # 指定取出N个不同元素 print(random.sample(val ...

  2. python产生随机值-random模块

    import random产生随机值的模块random.random() #获取一个随机的浮点值;help(random.random) #查看随机范围:0-1;random.uniform(1,10 ...

  3. 【Python】随机模块random & 日期时间のtime&&datetime

    ■ random 顾名思义,random提供了python中关于模拟随机的一些方法.这些方法都一看就懂的,不多说了: random.random() 返回0<n<=1的随机实数 rando ...

  4. [Swift]LeetCode528. 按权重随机选择 | Random Pick with Weight

    Given an array w of positive integers, where w[i] describes the weight of index i, write a function  ...

  5. python random从集合中随机选择元素

    1.使用python random模块的choice方法随机选择某个元素 from random import choice foo = ['a', 'b', 'c', 'd', 'e'] print ...

  6. python random 随机选择操作

    # -*- coding:utf-8 -*- import random arr = ['A','B','C','D','E','F'] #生成(0.0, 1.0)的随机数 print random. ...

  7. python 随机数模块 -- random

    一.概述 这个模块实现的伪随机数生成器. 对于整数,从区间选取.对于序列,随机元素. 在实线的,有功能来计算均匀分布,正态分布(高斯) ,对数正态分布,负指数,γ和β分布.对于生成的角度分布,冯·米塞 ...

  8. Python常用模块-随机数模块(random)

    Python常用模块-随机数模块(random) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.常用方法举例 #!/usr/bin/env python #_*_coding: ...

  9. Python 随机数 random

    1. Python seed() 函数     seed() 方法改变随机数生成器的种子,可以在调用其他随机模块函数之前调用此函数. seed( )是不能直接访问的,需要导入 random 模块,然后 ...

随机推荐

  1. 【Coursera】Security Introduction -Eighth Week(1)

    Security Introduction People With Bad Intent 今天,Bob 向 Alice 发送了一条 "Hello,Allice!" 的信息,他们希望 ...

  2. mini Linux制作过程(25/01)

    Mini Linux: 启动流程: 参考:https://blog.csdn.net/gatieme/article/details/50914250 https://linux.cn/article ...

  3. Spring中bean作用域属性scope

    关键字: spring中属性scope的prototype是什么意思   默认情况下,从bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spri ...

  4. python 时间元组转可视化时间

    >>> import time >>> time.asctime() 'Fri Jan 4 11:17:20 2019' >>> time.asc ...

  5. bugfree 数据库配置 显示No such file or directory

    把数据库服务器  localhost   改成127.0.0.1 sudo vi /etc/hosts 增加: 127.0.0.1   localhost 127.0.0.1   你的hostname ...

  6. ubuntu 14.04 server(amd64) 安装ros indigo

    1.添加软件源(添加了正确的软件源,操作系统就知道去哪里下载程序,并根据命令自动安装软件) sudo sh -c 'echo "deb http://packages.ros.org/ros ...

  7. STL_函数对象01

    1.自定义函数对象 1.1.简单例子: //函数对象 struct StuFunctor { bool operator() (const CStudent &stu1, const CStu ...

  8. Codeforces 496C - Removing Columns

    496C - Removing Columns 思路:暴力,用vis标记数组实时记录一下之前的行i+1和上一行i否全相等,false表示全相等. 代码: #include<bits/stdc++ ...

  9. Java 集合-List接口和三个子类实现

    List List:有序的 collection(也称为序列).此接口的用户可以对列表中每个元素的插入位置进行精确地控制.用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元素.与 ...

  10. 精伦盒子H1,插上USB,找不到对应的文件路径

    看USB的灯闪的挺正常的, 但就是不知道,该怎么mount 上去. 查了UDEV的资料, 发觉这个盒子虽然没有 udevmonitor命令, 却可以用  udevadm monitor 来监视udev ...