package main

import (
"math/rand"
"fmt"
"time"
) func main() {
/*
生成随机数random:
伪随机数,根据一定的算法公式算出来的。
math/rand
*/
num1 := rand.Int()
fmt.Println(num1) for i:=0;i<10;i++{
num :=rand.Intn(10) //[0,9]
fmt.Println(num)
}
rand.Seed(1000)
num2 := rand.Intn(10)
fmt.Println("-->",num2) //5 t1:=time.Now()
fmt.Println(t1)
fmt.Printf("%T\n",t1) //time.Time
//时间戳:指定时间,距离1970年1月1日0点0分0秒,之间的时间差值:秒,纳秒
timeStamp1:=t1.Unix() // 秒
fmt.Println(timeStamp1) //1580437473 timeStamp2:=t1.UnixNano()
fmt.Println(timeStamp2) //1580437473658483400 //step1:设置种子数,可以设置成时间戳
rand.Seed(time.Now().UnixNano())
for i:=0;i<10;i++{
//step2:调用生成随机数的函数
fmt.Println("-->",rand.Intn(100))
}
/*
[15,76]
[0,61]+15
[3,48]
[0,45]+3 Intn(n) // [0,n)
*/
num3:=rand.Intn(46)+3//[3,48]
fmt.Println(num3)
num4:=rand.Intn(62)+15 //[15,76]
fmt.Println(num4) }

  

Go_random的更多相关文章

随机推荐

  1. Wannafly Camp 2020 Day 5A Alternative Accounts

    There are n different accounts on the website, and some of them competed in the recent k contests. H ...

  2. clone()与clone(true)的用法

    clone() 方法生成被选元素的副本,包含子节点.文本和属性. 使用 clone(true) 方法在clone()的基础上还包括克隆元素的事件处理器.

  3. (转)git fetch + merge 和 git pull 的区别

    转自:http://blog.csdn.net/a19881029/article/details/42245955 Git fetch和git pull都可以用来更新本地库,它们之间有什么区别呢? ...

  4. 刷题76. Minimum Window Substring

    一.题目说明 题目76. Minimum Window Substring,求字符串S中最小连续字符串,包括字符串T中的所有字符,复杂度要求是O(n).难度是Hard! 二.我的解答 先说我的思路: ...

  5. Java上转型和下转型

    Java 转型问题其实并不复杂,只要记住一句话:父类引用指向子类对象. 什么叫父类引用指向子类对象,且听我慢慢道来. 从2个名词开始说起:向上转型(upcasting) .向下转型(downcasti ...

  6. LED Craft Light - How To Solve: Home Decoration Lighting

    Home décor usually comes with a certain period of theme or a specific style of furniture, which will ...

  7. python3练习100题——025

    原题链接:http://www.runoob.com/python/python-exercise-example25.html 题目:求1+2!+3!+...+20!的和. 我的代码: s =[] ...

  8. 03-Java基础语法【 流程控制语句】

    重要知识记录: 1.流程控制 顺序结构:根据编写的顺序,从上到下进行运行. 2.判断语句 1)判断语句1--if if(判断条件){ 执行语句: } 2)判断语句2--if...else if(判断条 ...

  9. VC++编译选项

    -优化- /O1 最小化空间 minimize space /Op[-] 改善浮点数一致性 improve floating-pt consistency /O2 最大化速度 maximize spe ...

  10. JSON解析及数据库操作实战篇

    代码: JSONObject json = JSONObject.parseObject(ubody);//得到整个json JSONObject AutoTable=json.getJSONObje ...