On 6/19/19 7:04 AM, Jan Bobek wrote: > + my $value = ($args{bigendian} > + ? ($args{value} >> (8 * $args{len} - $bitlen)) > + : $args{value}); ... > + $args{value} >>= $bitlen unless $args{bigendian};
I think this could be clearer without modifying $args. I mis-read these the first time around. Perhaps my $bitpos = 0; my $bitend = 8 * $args{len}; while ($bitpos < $bitend) { ... my $value = $args{value} >> ($args{bigendian} ? $bitend - $bitpos - $bitlen : $bitpos); ... $bitpos += $bitlen; } > +sub randint_constr(%) > +{ > + my (%args) = @_; > + my $bitlen = $args{bitlen}; > + my $halfrange = 1 << ($bitlen - 1); > + > + while (1) { > + my $value = int(rand(2 * $halfrange)); > + $value -= $halfrange if defined $args{signed} && $args{signed}; > + $value &= ~$args{fixedbitmask} if defined $args{fixedbitmask}; > + $value |= $args{fixedbits} if defined $args{fixedbits}; > + > + if (defined $args{constraint}) { > + if (!($args{constraint} >> 63)) { > + $value = $args{constraint}; > + } elsif ($value == ~$args{constraint}) { > + next; > + } > + } I don't understand what you're doing here with {constraint}. Some additional commentary would help. r~