python math random
很有用个的工具
值得好好看看,这是作者(python发明者)对于工作中使用到的大多数场景的提炼
//test.py
1 import math
2
3 print abs(-10)
4 print math.ceil(4.1)
5 print cmp(1,2)
6 print math.exp(2)
7 print math.fabs(-10)
8 print math.log(math.e)
9 print math.log(100, 10)
10 print math.log10(100)
11 print max(1, 2)
12 print max((1, 2))
13 print max((1, 2), (3, 4))
14 print min(1,2)
15 print math.modf(-10.3456)
16 print math.pow(2, 2)
17 print round(1.4587604, 3)
18 print math.sqrt(4)
19
20 print math.acos(0.7)
21 print math.asin(0.7)
22 print math.atan(12)
23 print math.atan2(10, 3)
24 print math.hypot(2, 3)
25 print math.sin(30)
26 print math.tan(30)
27 print math.degrees(0.8)
28 print math.radians(90)
29 print math.radians(360)
30
31 import random
32
33 nums = (1, 2, 3, 4, 5)
34 print random.choice(nums)
35 print random.choice(range(100))
36 print random.randrange(100)
37 print random.randrange(0, 100, 3)
38 print random.random()
39 v_nums = list(nums)
40 random.shuffle(v_nums)
41 print v_nums
42 print random.uniform(10.3, 27.8)
//result
# python test.py
10
5.0
-1
7.38905609893
10.0
1.0
2.0
2.0
2
2
(3, 4)
1
(-0.34559999999999924, -10.0)
4.0
1.459
2.0
0.795398830184
0.775397496611
1.48765509491
1.27933953232
3.60555127546
-0.988031624093
-6.40533119665
45.8366236105
1.57079632679
6.28318530718
1
90
2
48
0.343898314122
[3, 2, 5, 1, 4]
13.7044793568
Finally:
需要时候,可以回来看一下这个例子,立马就能知道怎么用这些个函数了
python math random的更多相关文章
- 【转载】python 模块 - random生成随机数模块
随机数种子 要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成的随机数字是完全相同的: random.seed(1) 这样random.randint(0,6, (4,5)) ...
- Chrome V8引擎系列随笔 (1):Math.Random()函数概览
先让大家来看一幅图,这幅图是V8引擎4.7版本和4.9版本Math.Random()函数的值的分布图,我可以这么理解 .从下图中,也许你会认为这是个二维码?其实这幅图告诉我们一个道理,第二张图的点的分 ...
- Math.random()
Math.random() 日期时间函数(需要用变量调用):var b = new Date(); //获取当前时间b.getTime() //获取时间戳b.getFullYear() //获取年份b ...
- 如何在一个页面后面随机跳转到多个链接地址Math.floor()和Math.random()
点击一个标签随机跳转到多个链接地址,主要运用javascript中的Math.floor()和Math.random()方法 floor(x) 方法是向下去整数 参数为任意数值或表达式. floor( ...
- 验证码点击刷新 this.src=this.src+'?'+Math.random()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Random.nextint() 和Math.random()的区别
Random.nextint() 和Math.random()的区别 Java代码 Random rand = new Random(); long startTime = System.nano ...
- js中Math.random()生成指定范围数值的随机数
http://www.111cn.net/wy/js-ajax/57062.htm Math.random() 这个方法相信大家都知道,是用来生成随机数的.不过一般的参考手册时却没有说明如何用这个方法 ...
- javascript 中根据sort 方法随机数组 (Math.random)
var arr = [1,2,3,4,5,6,7,8,9,10]; function Arandom(a,b){ return (Math.random() > 0.5) ? 1 : -1;; ...
- python使用random函数生成随机数
python使用random函数来生成随机数,常用的方法有: import random #生成0-1之间的数(不包括0和1) random.random() #生成1-5之间的随机整数(包括1和5) ...
随机推荐
- eclipse启动报错:Could not create the java virtual machine
用maven.springboot开发时,安装了当时最新版的eclipse(3.5.5).eclipse解压版的非常方便,想先安装了看看.暂时没有升级其他软件. 打开的时候报错: 原因其实就是还木有升 ...
- redis数据持久化的两种方式
1,AOF AOF持久化以日志的形式记录服务器所处理的每一个写.删除操作,查询操作不会记录,以文本的方式append记录,可以打开文件看到详细的操作记录.(相同数量的数据集而言,AOF文件通常要大于R ...
- 主席树||可持久化线段树||离散化||[CQOI2015]任务查询系统||BZOJ 3932||Luogu P3168
题目: [CQOI2015]任务查询系统 题解: 是一道很经典的题目.大体思路是抓优先级来当下标做主席树,用时刻作为主席树的版本.然而优先级范围到1e7去了,就离散化一遍.然后把每个事件的开始(s). ...
- nvidia-smi failed because it couldn't communicate with the nvidia driver
Ubuntu装好CUDA之后过段时间提示NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. NV ...
- LDAP - 轻量目录访问协议
LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP
- 老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分
老师的blog整理 python基础部分: 宝哥blog: https://www.cnblogs.com/guobaoyuan/ 开哥blog: https://home.cnblogs.com/u ...
- FutureTask的用法及两种常用的使用场景
FutureTask可用于异步获取执行结果或取消执行任务的场景.通过传入Runnable或者Callable的任务给FutureTask,直接调用其run方法或者放入线程池执行,之后可以在外部通过Fu ...
- 深入 Vue 生命周期
深入 Vue 生命周期 这篇博客将会从下面四个常见的应用诠释组件的生命周期,以及各个生命周期应该干什么事 1.单组件的生命周期 2.父子组件的生命周期 3.兄弟组件的生命周期 4.宏mixin的生命周 ...
- 模板倍增LCA 求树上两点距离 hdu2586
http://acm.hdu.edu.cn/showproblem.php?pid=2586 课上给的ppt里的模板是错的,wa了一下午orz.最近总是被坑啊... 题解:树上两点距离转化为到根的距离 ...
- C和C指针小记(十)-函数
1.函数的定义 函数的定义就是函数体的实现. 语法: 类型 函数名(形式参数) 代码块 函数返回类型和函数名分开写是代码风格的问题,现代语言如swift返回值在函数名和参数表的后面,这样使得某些工程工 ...