很有用个的工具

值得好好看看,这是作者(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的更多相关文章

  1. 【转载】python 模块 - random生成随机数模块

    随机数种子 要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成的随机数字是完全相同的: random.seed(1) 这样random.randint(0,6, (4,5)) ...

  2. Chrome V8引擎系列随笔 (1):Math.Random()函数概览

    先让大家来看一幅图,这幅图是V8引擎4.7版本和4.9版本Math.Random()函数的值的分布图,我可以这么理解 .从下图中,也许你会认为这是个二维码?其实这幅图告诉我们一个道理,第二张图的点的分 ...

  3. Math.random()

    Math.random() 日期时间函数(需要用变量调用):var b = new Date(); //获取当前时间b.getTime() //获取时间戳b.getFullYear() //获取年份b ...

  4. 如何在一个页面后面随机跳转到多个链接地址Math.floor()和Math.random()

    点击一个标签随机跳转到多个链接地址,主要运用javascript中的Math.floor()和Math.random()方法 floor(x) 方法是向下去整数 参数为任意数值或表达式. floor( ...

  5. 验证码点击刷新 this.src=this.src+'?'+Math.random()

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Random.nextint() 和Math.random()的区别

    Random.nextint() 和Math.random()的区别 Java代码   Random rand = new Random(); long startTime = System.nano ...

  7. js中Math.random()生成指定范围数值的随机数

    http://www.111cn.net/wy/js-ajax/57062.htm Math.random() 这个方法相信大家都知道,是用来生成随机数的.不过一般的参考手册时却没有说明如何用这个方法 ...

  8. 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;; ...

  9. python使用random函数生成随机数

    python使用random函数来生成随机数,常用的方法有: import random #生成0-1之间的数(不包括0和1) random.random() #生成1-5之间的随机整数(包括1和5) ...

随机推荐

  1. HDOJ HDU 1850 Being a Good Boy in Spring Festival

    Description 一年在外 父母时刻牵挂 春节回家 你能做几天好孩子吗 寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场 悄悄给爸爸买个小礼物 主动地 强烈地 要求洗一次碗 某一天早起 给爸妈用心地 ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 I. Lattice's basics in digital electronics 阅读题加模拟题

    题意:https://nanti.jisuanke.com/t/31450 题解:题目很长的模拟,有点uva的感觉 分成四步 part1 16进制转为二进制string 用bitset的to_stri ...

  3. express链接mysql, 用数据库连接池管理链接

    1.在API的开发当中,数据库的处理显得尤为重要,express 工程 链接mysql数据库有很好的模板可以借鉴. 1.1 创建数据库链接 新建一个DB目录,在DB目录下新建文件 db.js 内容如下 ...

  4. English class 81:How Vulnerability can make our lives better?

    1,can we come off as weak if we show imperfections? 2,The first thing I look for in you and the last ...

  5. 回归cgi、fastcgi原理,解释、解决异常 fastcgi支持分布式计算的原因

    小结: 0.结构图 client-request ---> cgi/fastcgi (interface/server)  ---> cgi/fastcgi program/applica ...

  6. 2015年蓝桥杯省赛A组c++第1题

    /* 方程: a^2 + b^2 + c^2 = 1000 这个方程有整数解吗?有:a,b,c=6,8,30 就是一组解. 你能算出另一组合适的解吗? 请填写该解中最小的数字. 注意:你提交的应该是一 ...

  7. jdbc实现分页,需要前端传当前页码

    1.封装一个公共实体类用于返回:实体数据,当前页,总页数,总条数,每页多少条 public class PageInfo<T> { //一页显示的记录数 private int numPe ...

  8. 洛谷P1966 火柴排队 贪心+离散化+逆序对(待补充QAQ

    正解: 贪心+离散化+逆序对 解题报告: 链接在这儿呢quq 这题其实主要难在想方法吧我觉得?学长提点了下说用贪心之后就大概明白了,感觉没有很难 但是离散化这里还是挺有趣的,因为并不是能很熟练地掌握离 ...

  9. SSH端口转发详解及实例-转载

    作者:珂儿吖 出处:http://www.cnblogs.com/keerya/ 目录 1.1 SSH端口转发的两大功能 实验一:实现SSH端口转发——本地转发 实验二.实现SSH端口转发——远程转发 ...

  10. 网页制作中规范使用DIV+CSS命名规则,可以改善优化功效特别是团队合作时候可以提供合作制作效率,具体DIV CSS命名规则CSS命名大全内容如下:

    页头:header  如:#header{属性:属性值;}或.header{属性:属性值;},也许你需要了解class与id区别及用法登录条:loginBar         标志:logo      ...