randz

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: Apache-2.0 Imports: 2 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.WithRandomReader(ExampleReader))
	s, err := r.ReadString(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 DefaultRandomSource = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

Variables

View Source
var (
	DefaultReader io.Reader = NewReader()
)

Functions

func ReadString

func ReadString(length int) (random string, err error)

Types

type Reader

type Reader struct {
	RandomSource string
	RandomReader io.Reader
}

func NewReader

func NewReader(opts ...ReaderOption) *Reader

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) ReadString

func (r *Reader) ReadString(length int) (random string, err error)

type ReaderOption

type ReaderOption func(r *Reader)

func WithRandomReader

func WithRandomReader(reader io.Reader) ReaderOption

func WithRandomSource

func WithRandomSource(str string) ReaderOption

Jump to

Keyboard shortcuts

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