github.com/tunabay/go-bitarray@v1.3.1/bitarray_rand_example_test.go (about)

     1  // Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
     2  // Use of this source code is governed by the MIT license that can be found in
     3  // the LICENSE file.
     4  
     5  package bitarray_test
     6  
     7  import (
     8  	"fmt"
     9  	"math/rand"
    10  
    11  	"github.com/tunabay/go-bitarray"
    12  )
    13  
    14  func ExampleRand() {
    15  	ba, err := bitarray.Rand(42)
    16  	if err != nil {
    17  		panic(err)
    18  	}
    19  
    20  	fmt.Printf("% s\n", ba)
    21  }
    22  
    23  func ExamplePseudoRand() {
    24  	rand.Seed(1234)
    25  
    26  	ba := bitarray.PseudoRand(42, nil)
    27  	fmt.Printf("% s\n", ba)
    28  
    29  	// Output:
    30  	// 11000000 00001110 01011101 01100111 11000010 01
    31  }
    32  
    33  func ExamplePseudoRand_customSource() {
    34  	myRand := rand.New(rand.NewSource(1234))
    35  
    36  	ba0 := bitarray.PseudoRand(42, myRand)
    37  	ba1 := bitarray.PseudoRand(13, myRand)
    38  	fmt.Printf("% s\n", ba0)
    39  	fmt.Printf("% s\n", ba1)
    40  
    41  	// Output:
    42  	// 11000000 00001110 01011101 01100111 11000010 01
    43  	// 01010011 10001
    44  }