Skip to content

Commit

Permalink
fix: Fix UniformSampler
Browse files Browse the repository at this point in the history
  • Loading branch information
sp301415 committed Sep 8, 2024
1 parent 5b4aec5 commit 1683f11
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions math/csprng/uniform_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewUniformSamplerWithSeed[T num.Integer](seed []byte) *UniformSampler[T] {
prng: prng,

buf: make([]byte, bufSize),
ptr: 0,
ptr: bufSize,

byteSizeT: byteSizeT,
maxT: T(num.MaxT[T]()),
Expand All @@ -82,17 +82,17 @@ func (s *UniformSampler[T]) Sample() T {

var res T
switch s.byteSizeT {
case 8:
case 1:
res = T(uint64(s.buf[s.ptr+0]))
case 16:
case 2:
res = T(uint64(s.buf[s.ptr+0]))
res |= T(uint64(s.buf[s.ptr+1]) << 8)
case 32:
case 4:
res = T(uint64(s.buf[s.ptr+0]))
res |= T(uint64(s.buf[s.ptr+1]) << 8)
res |= T(uint64(s.buf[s.ptr+2]) << 16)
res |= T(uint64(s.buf[s.ptr+3]) << 24)
case 64:
case 8:
res = T(uint64(s.buf[s.ptr+0]))
res |= T(uint64(s.buf[s.ptr+1]) << 8)
res |= T(uint64(s.buf[s.ptr+2]) << 16)
Expand Down

0 comments on commit 1683f11

Please sign in to comment.