LoginSignup
1
0

More than 1 year has passed since last update.

Go lang / rand.Seed(time.Now().UnixNano()) used as value / #go

Last updated at Posted at 2020-03-16
// https://golang.org/pkg/math/rand/

package main

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

func main() {
	// NG
	seed_result := rand.Seed(time.Now().UnixNano())

	// OK
	// Seed does not need return value
	// rand.Seed(time.Now().UnixNano())

	fmt.Println(rand.Int())
}

Seed生成した値を使い回すのではなく、一回だけ設定すれば良いみたいだ。なので帰り値は要らない。

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0