-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework structure, add configuration options
- Loading branch information
Showing
4 changed files
with
124 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package fill | ||
|
||
import "math/rand/v2" | ||
|
||
// A Filler fills in random values. | ||
type Filler struct { | ||
MinSize int // Arbitrary lower bound for value sizes. | ||
MaxSize int // Arbitrary upper bound for value sizes. | ||
Runes []rune // Runes to select from when filling strings. | ||
NeverNil bool // Never select nil for fillable values. | ||
RandSource *rand.Rand // Custom rand source. | ||
} | ||
|
||
var Base64 = []rune{ | ||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', | ||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', | ||
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', | ||
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', | ||
'8', '9', '+', '/', | ||
} | ||
|
||
func (f *Filler) intN(n int) int { | ||
if n == 0 { | ||
return 0 | ||
} else if f.RandSource == nil { | ||
return rand.IntN(n) | ||
} else { | ||
return f.RandSource.IntN(n) | ||
} | ||
} | ||
|
||
func (f *Filler) int64() int64 { | ||
if f.RandSource == nil { | ||
return rand.Int64() | ||
} else { | ||
return f.RandSource.Int64() | ||
} | ||
} | ||
|
||
func (f *Filler) uint64() uint64 { | ||
if f.RandSource == nil { | ||
return rand.Uint64() | ||
} else { | ||
return f.RandSource.Uint64() | ||
} | ||
} | ||
|
||
func (f *Filler) float64() float64 { | ||
if f.RandSource == nil { | ||
return rand.Float64() | ||
} else { | ||
return f.RandSource.Float64() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package fill | ||
|
||
var zeroFiller = Filler{NeverNil: true} | ||
|
||
// Zero fills a value with zero-valued data. | ||
func Zero(a any) { zeroFiller.Fill(a) } |