O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter03/recipe08.
  2. Navigate to the directory.
  3. Create the rand.go file with the following content:
        package main        import (          crypto "crypto/rand"          "fmt"          "math/big"          "math/rand"        )        func main() {          sec1 := rand.New(rand.NewSource(10))          sec2 := rand.New(rand.NewSource(10))          for i := 0; i < 5; i++ {            rnd1 := sec1.Int()            rnd2 := sec2.Int()            if rnd1 != rnd2 {              fmt.Println("Rand generated non-equal sequence")              break            } else {              fmt.Printf("Math/Rand1: %d , Math/Rand2: %d\n", rnd1, rnd2)            }          }          for i := 0; i < 5; i++ {            safeNum := NewCryptoRand()            safeNum2 := NewCryptoRand()            if safeNum == safeNum2 {              fmt.Println("Crypto generated equal numbers")              break            } else {              fmt.Printf("Crypto/Rand1: %d , Crypto/Rand2: %d\n", safeNum, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required