Python random模块random/uniform/randint/choice/getrandbits/shuffle/choice/sample随机函数
1.random.random()
返回0<=n<1之间的随机实数n
2. random.uniform()
弥补了上面函数的不足,它可以设定浮点数的范围,一个是上限,一个是下限。
3. random.randint()
随机生成一个整数int类型,可以指定这个整数的范围,同样有上限和下限值
4. random.choice(seq)
从任何序列,比如list列表中,选取一个随机的元素返回,可以用于字符串、列表、元组等
5. random.getrandbits(n)
以长整型形式返回n个随机位
6. random.shuffle(seq[, random])
将一个序列中的元素,随机打乱的话可以用这个函数方法
7. random.sample(seq, n)
从序列seq中选择n个随机且独立的元素。从指定的序列中,随机的截取指定长度的片段,不作原地修改。
举例:
from random import randint, sample
date = [randint(10,20) for _ in range(10)]
c = sample(date, 5)
print(c)

Python random模块random/uniform/randint/choice/getrandbits/shuffle/choice/sample随机函数的更多相关文章
- python shutil模块&random模块
shutil模块 import shutil shutil.copyfileobj(open("os_.py", "r"), open("os_2.p ...
- python 随机数模块 -- random
一.概述 这个模块实现的伪随机数生成器. 对于整数,从区间选取.对于序列,随机元素. 在实线的,有功能来计算均匀分布,正态分布(高斯) ,对数正态分布,负指数,γ和β分布.对于生成的角度分布,冯·米塞 ...
- Python:time模块/random模块/os模块/sys模块
time 模块 #常用方法 1.time.sleep(secs) (线程)推迟指定的时间运行.单位为秒. 2.time.time() 获取当前时间戳 python中时间日期格式化符号: %y 两位数的 ...
- python 基本模块 random、os、sys
一.random模块 所有关于随机相关的内容都在random模块中 import random print(random.random()) # 0-1⼩数 print(random.uniform( ...
- python常用模块: random模块, time模块, sys模块, os模块, 序列化模块
一. random模块 import random # 任意小数 print(random.random()) # 0到1的任意小数 print(random.uniform(-10, 10)) # ...
- python常用模块——random模块
参考博客:http://www.360doc.com/content/14/0430/11/16044571_373443266.shtml 今天突然想起python该怎么生成随机数?查了一下,贴出实 ...
- python之模块random,time,os,sys,序列化模块(json,pickle),collection
引入:什么是模块: 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类型. 1.使用python编写的代码(.py ...
- python 之模块random
随机形成字母和数字组成的五位字符码. [root@localhost python]# vim timee.py import random def coder(): code = '' for i ...
- python 随机模块random
随机推荐
- phpcms v9 的表单向导功能的使用方法 附多个案例
本文主要介绍phpcms v9的表单向导功能是如何使用的,并副多个案例讲解: 先介绍一下v9 的表单向导如何使用 表单向导做的很实用,生成一个表单,常用的是把它作为一个留言板,或者在招聘栏目作为一个供 ...
- CentOS7(linux) 通过服务名查询安装目录
#ps aux|grep nginx root 1231 0.0 0.0 46336 956 ? Ss 04:21 0:00 nginx: master process /usr/sbin/nginx ...
- Spring <context:annotation-config> 与<context-component-scan> 的作用
<context:annotation-config> 与<context-component-scan> 的作用 <context:annotation-config& ...
- 【待补】splay 模板
#define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h&g ...
- bilibili的直播第三方IJKMediaFramework.framework下载打包使用教程
参考和引用的地址: http://www.code4app.com/thread-8941-1-1.html http://blog.csdn.net/cccallen/article/details ...
- malloc函数 链表
https://baike.baidu.com/item/malloc函数 malloc的全称是memory allocation,中文叫动态内存分配,用于申请一块连续的指定大小的内存块区域以void ...
- influxdb服务器 relay
https://www.influxdata.com/time-series-platform/influxdb/ https://www.xusheng.org/blog/2016/07/30/pe ...
- 部署WEB项目到服务器(一)安装java到linux服务器(Ubuntu)详解
突发奇想,想在自己电脑上部署一个web网站. 1,首先要下载一个适合已经安装的linux系统的java版本. 登录网址:http://www.oracle.com/technetwork/java/j ...
- 第8章 用SQL语句操作数据
SQL的组成: (1)DML(Data Manipiation Language ,数据操作语言,)用来插入,修改和删除数据库中的数据,如:INSERT,UPDATE,DELETE等. (2)DDL( ...
- js字符串拼接
1. 2. 3.