본문 바로가기
Go/Packages

[Go] Package math

by llHoYall 2020. 10. 27.

Package math

Package math provides basic constants and mathematical functions.

Package rand

Package rand implements pseudo-random number generators.

Methods

Seed

Seed uses the provided seed value to initialize the default Source to a deterministic state.

Seed values that have the same remainder when divided by 2^31 - 1 generate the same pseudo-random sequence.

Seed, unlike the Rand.Seed method, is safe for concurrent use.

func Seed(seed int64)

Intn

Intn returns, as an int, a non-negative pseudo-random number in [0, n) from the default Source.

It panics if n <= 0.

func Intn(n int) int

Usage

package main

import (
  "fmt"
  "math/rand"
  "time"
)

func main() {
  seed := time.Now().Unix()
  rand.Seed(seed)
  randNum := rand.Intn(100) + 1
  fmt.Println(randNum)
}

'Go > Packages' 카테고리의 다른 글

[Go] Package log  (0) 2020.11.30
[Go] Package bufio  (0) 2020.10.31
[Go] Package errors  (0) 2020.10.29
[Go] Package strconv  (0) 2020.10.26
[Go] Package strings  (0) 2020.10.26

댓글