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. nice-validator判断表单是否验证通过

    $("#formSurvery").isValid(function(is){ if(is){ alert("通过!") } } 如果is为false则表示不通 ...

  3. 逆战:微信小程序(一)

    简介 小程序是一种不需要下载安装即可使用的应用,它实现了应用"触手可及"的梦想,用户扫一扫或者搜一下即可打开应用.也体现了"用完即走"的理念,用户不用关心是否安 ...

  4. 给阿里云主机添加swap分区,解决问题:c++: internal compiler error: Killed (program cc1plus)

    前言 今天安装spdlog,一个快速得C++日志库,按照文档步骤,不料出现了一堆错误,像c++: internal compiler error: Killed (program cc1plus)等一 ...

  5. 简单易用,用Powershell劫持Windows系统快捷键

    POC:  $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("des ...

  6. manifold learning

    MDS, multidimensional scaling, 线性降维方法, 目的就是使得降维之后的点两两之间的距离尽量不变(也就是和在原是空间中对应的两个点之间的距离要差不多).只是 MDS 是针对 ...

  7. eclipse运用经验

    1.eclipse粘贴字符串添加转义符 2.eclipse的jdk版本切换 1.Window—Preferences—Java—Compiler—右侧面板设置为1.6 2.Window—Prefere ...

  8. JAVASCRIPT实现的WEB页面跳转以及页面间传值方法

    在WEB页面中,我们实现页面跳转的方法通常是用LINK,BUTTON LINK ,IMG LINK等等,由用户点击某处,然后直接由浏览器帮我们跳转. 但有时候,需要当某事件触发时,我们先做一些操作,然 ...

  9. 详解C++11智能指针

    前言 C++里面的四个智能指针: auto_ptr, unique_ptr,shared_ptr, weak_ptr 其中后三个是C++11支持,并且第一个已经被C++11弃用. C++11智能指针介 ...

  10. e.printStackTrace()打印在哪里以及如何e.printStackTrace()的内容打印在日志中

    1.e.printStackTrace()打印在哪里 在catch中的e.printStackTrace()将打印到控制台 2.e.printStackTrace()打印的内容是什么 如下代码: im ...