github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/crypto/rand/example_test.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rand_test 6 7 import ( 8 "github.com/shogo82148/std/bytes" 9 "github.com/shogo82148/std/crypto/rand" 10 "github.com/shogo82148/std/fmt" 11 ) 12 13 // この例は、rand.Readerから暗号的に安全な疑似乱数を10個読み込み、バイトスライスに書き込みます。 14 func ExampleRead() { 15 c := 10 16 b := make([]byte, c) 17 _, err := rand.Read(b) 18 if err != nil { 19 fmt.Println("error:", err) 20 return 21 } 22 // スライスは、ゼロの代わりにランダムなバイトを含んでいるべきです。 23 fmt.Println(bytes.Equal(b, make([]byte, c))) 24 25 // Output: 26 // false 27 }