randz

package
v0.0.66 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Example
package main

import (
	"bytes"
	"fmt"
	"log"

	randz "github.com/kunitsucom/util.go/crypto/rand"
)

var ExampleReader = bytes.NewBufferString("" +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production." +
	"This is a test Reader for example. Please use crypto/rand's Reader in production.",
)

func main() {
	r := randz.NewReader(randz.WithNewReaderOptionRandomReader(ExampleReader))
	s, err := randz.ReadString(r, 128)
	if err != nil {
		log.Printf("(*randz.Reader).ReadString: %v", err)
		return
	}

	fmt.Printf("very secure random string: %s", s)
}
Output:

very secure random string: Wqr1gr1gjg2n12gUnjmn0gox0gn6jvyunugSunj1ng31ngl07y2xv0jwmn1gUnjmn0grwgy0xm3l2rxwuWqr1gr1gjg2n12gUnjmn0gox0gn6jvyunugSunj1ng31ngl

Index

Examples

Constants

View Source
const DefaultStringReaderRandomSource = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

Variables

View Source
var (
	StringReader = NewReader()
)

Functions

func NewReader

func NewReader(opts ...NewReaderOption) io.Reader

func ReadString

func ReadString(random io.Reader, length int) (string, error)

Types

type NewReaderOption added in v0.0.57

type NewReaderOption func(r *reader)

func WithNewReaderOptionRandomReader added in v0.0.57

func WithNewReaderOptionRandomReader(random io.Reader) NewReaderOption

func WithNewReaderRandomSource added in v0.0.57

func WithNewReaderRandomSource(s string) NewReaderOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL