Random number issue in golang

Viewed 3750

This is the code I'm working with:

package main
import "fmt"
import "math/rand"

func main() {
    code := rand.Intn(900000)
    fmt.Println(code)
}

It always returns 698081. I don't understand, what the is problem?

https://play.golang.org/p/XisNbqCZls

Edit:

I tried rand.Seed

package main

import "fmt"
import "time"
import "math/rand"

func main() {
    rand.Seed(time.Now().UnixNano())
    code := rand.Intn(900000)
    fmt.Println(code)
}

There is no change. Now it always returns 452000

https://play.golang.org/p/E_Wfm5tOdH

https://play.golang.org/p/aVWIN1Eb84

1 Answers
Related