github.com/MetalBlockchain/metalgo@v1.11.9/utils/sampler/uniform.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package sampler 5 6 // Uniform samples values without replacement in the provided range 7 type Uniform interface { 8 Initialize(sampleRange uint64) 9 // Sample returns length numbers in the range [0,sampleRange). If there 10 // aren't enough numbers in the range, false is returned. If length is 11 // negative the implementation may panic. 12 Sample(length int) ([]uint64, bool) 13 14 Next() (uint64, bool) 15 Reset() 16 } 17 18 // NewUniform returns a new sampler 19 func NewUniform() Uniform { 20 return &uniformReplacer{ 21 rng: globalRNG, 22 } 23 } 24 25 // NewDeterministicUniform returns a new sampler 26 func NewDeterministicUniform(source Source) Uniform { 27 return &uniformReplacer{ 28 rng: &rng{ 29 rng: source, 30 }, 31 } 32 }