随机数产生机制 解释器将代码加载到内存的处理
import time, random
def m(t=3000 * 20 * 1 * random.randint(0, 20)):
print(t)
print(time.time())
time.sleep(1)
[m() for i in range(8)]
420000
1526986984.627107
420000
1526986985.6277814
420000
1526986986.6284676
420000
1526986987.6290512
420000
1526986988.6297226
420000
1526986989.6304398
420000
1526986990.6310155
420000
1526986991.6319053
每次运行程序,随机值确定
改变睡眠时间,仍然
import time, random
def m(t=3000 * 20 * 1 * random.randint(0, 20) * time.time()):
print(t)
print(time.time())
time.sleep(10)
[m() for i in range(8)]
1007811503605215.2
1526987126.6745687
1007811503605215.2
1526987136.6750913
1007811503605215.2
1526987146.6759949
1007811503605215.2
1526987156.6767433
1007811503605215.2
1526987166.6768875
import time, random
def m(t=3000 * 20 * 1 * random.randint(0, 20)):
print(t)
print(time.time())
time.sleep(1)
[m(3000 * 20 * 1 * random.randint(0, 20)) for i in range(8)]
1080000
1526987280.9112635
780000
1526987281.9114752
540000
1526987282.9115393
480000
1526987283.912519
解释器初始化 环境时,已经赋值
python 变量类型
import time, random
def m(t=3000 * 20 * 1, to_shuffle=True, to_shuffle_l=[0, 18]):
if to_shuffle:
t = t * random.randint(to_shuffle_l[0], to_shuffle_l[1])
print(t)
print(time.time())
time.sleep(1)
[m() for i in range(8)]
package tts.producing; import java.util.Random; public class MyTest { public int randomPositiveInt() { int i = new Random().nextInt(); return Math.abs(i); } public String randomPositiveIntWithTm() { int i = this.randomPositiveInt(); long tmMillis = System.currentTimeMillis(); String r = String.valueOf(i) + "_" + String.valueOf(tmMillis); return r; } public static void main(String[] args) { MyTest t = new MyTest(); String d = t.randomPositiveIntWithTm(); System.out.println(d); } }