Skip to content

Instantly share code, notes, and snippets.

@djberg96
Last active June 24, 2021 18:55
Show Gist options
  • Save djberg96/6cb41a2e45724d529578a072138c5243 to your computer and use it in GitHub Desktop.
Save djberg96/6cb41a2e45724d529578a072138c5243 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"math/rand"
)
func randate() time.Time {
min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2070, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min
sec := rand.Int63n(delta) + min
return time.Unix(sec, 0)
}
func main() {
fmt.Println("Random:", randate()) /* go run produces same date every time */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment