带时间包的随机数

So I'm looking to generate a random number in Go, and the recommended way of doing this is apparently to use something like this:

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

func random(min, max int) int {
    rand.Seed(time.Now().Unix())
    return rand.Intn(max - min) + min
}

But this seems like a solution where the random number isn't random if two people run this script at the same time. The seed is apparently the time of execution, and this could very well be the same in some cases.

Isn't this a pretty inaccurate way of generating a random number? I ran it a couple times, and it just gives me the same number if I run it fast enough. Isn't there a better solution for a random number? Like, for example, using cryptography or something as the seed? Time just doesn't seem like the best seed.

math/rand isn't meant for anything secure. For secure randomness, use crypto/rand.

If you simply want to get rid of the 1-second granularity, use time.Now().UnixNano() instead of time.Now().Unix(). You can also mix in data that's likely to vary between systems, like os.Getpid() or a hardware address from net.Interfaces(), to prevent different systems "accidentally" generating the same value at the same time (again, this is not a security measure).

For something in between, read 64 bits from the Reader in crypto/rand, and use that to seed math/rand :)